r - ggplot2:几何区域没有出现
问题描述
几个月前,我使用了一个脚本,使用 ggplot2 构建了一个堆积面积图。我现在正试图用类似的数据重新做,但我面临着没有显示区域的问题。在此之前,我检查了数据集是否可以制作条形图。
library(ggplot2)
library(reshape2)
SampleID=c("SiteA","SiteB","SiteC","SiteD")
Species1=c(0.1,0.2,0.3,0.6)
Species2=c(0.15,0.25,0.35,0.4)
Species3=c(0.05,0,0.4,0.3)
Species4=c(0,0.05,0.05,0.9)
data=data.frame(SampleID,Species1,Species2,Species3,Species4)
mdata=melt(data)
ggplot(mdata, aes(x=SampleID, y=value,fill=variable,order=SampleID))+
geom_area(stat = 'identity',colour='black')
如您所见,区域没有出现。任何人都会有建议吗?谢谢!
解决方案
根据 heck1 的评论,我将字符名称替换为数字。但是,我必须更改融化功能才能使其正常工作。
library(ggplot2)
library(reshape2)
SampleID=c(1,2,3,4)
Species1=c(0.1,0.2,0.3,0.6)
Species2=c(0.15,0.25,0.35,0.4)
Species3=c(0.05,0,0.4,0.3)
Species4=c(0,0.05,0.05,0.9)
data=data.frame(SampleID,Species1,Species2,Species3,Species4)
mdata=melt(data,id.vars = "SampleID", measure.vars = c("Species1","Species2","Species3","Species4"))
mdata=as.data.frame(mdata)
ggplot(mdata, aes(x=SampleID, y=value,fill=variable,order=SampleID))+
geom_area(stat = 'identity',colour='black')
推荐阅读
- google-chrome-devtools - 与真实移动视图相比,Chrome DevTools 无法提供准确的移动视图
- python - 为什么 pipenv 不使用它的轮子缓存?
- php - PHP 表单从外部脚本 XML 数据中捕获 POST
- phonegap - 滑动打开左右面板
- angular - Angular 6 和 bootstrap 3 有轮播吗?
- python - 当我运行我的代码时,它返回'[]'。我怎样才能解决这个问题?
- android - 带有 setOnClickListener 的 RecyclerView
- vb.net - 为什么在调试输出中出现“System.Data.SQLite.dll”的“Disposed Exceptions”?
- python - 根据日期列过滤和创建列
- azure - 在 Azure 应用程序网关中拒绝动态公共 IP 配置的策略