使用ggplot2更正Stacked区域图中的缺失值 [英] Correct for missing values in a Stacked area plot using ggplot2
问题描述
我一直在尝试重新组合此信息堆积的酒吧/面积阴谋。尽管如此,我仍然有一些缺失值的问题。
以下是我的数据: https:// www.dropbox.com/sh/pnkspwnn1qslm6u/JapTKCwqMS
我运行的是
<$ p
名称(wa)= c(code> wa = read.table('wa_class.txt',sep =,header = F,na.string =0类,‘月’,‘月’,‘月’,‘月’,‘月’,‘君’,‘月’,‘月’,‘月’,‘月’,‘月’,‘月’ )
wam = melt(wa)
wam $ variablen = as.numeric(wam $ variable)
看起来如何
>头(wam)
类变量值变量n
1 Actinobacteria Jan 38.115163 1
2 Flavobacteria Jan NA 1
3 Sphingobacteria Jan 3.640469 1
4 Alphaproteobacteria Jan 13.631663 1
5 Betaproteobacteria_b28 1月3.718671 1
Betaproteobacteria Jan 14.732354 1
ggplot(na.omit(wam [,c(Class,value,variablen)))), aes(wam,x = variablen,y = value,fill = Class))+ geom_area(color =black)+ geom_linerange(aes(ymax = value),position =stack)+ scale_x_continuous(breaks = 1:max (wam $ variablen))+ labs(title =Water,x =Month,y =Relative abundance(%))
...所以我试图在我绘制的变量上使用na.omit来校正缺失的值。但是,我在图中获得了层,例如(见Dropbox文件夹)。
我发现这篇文章(见保管箱文件夹)已经修正,但似乎只有一个。我无法复制它,因为链接到数据是死的。
任何帮助真的很感谢!
谢谢,
Jo
将零读取为零值。如果你不使用 na.string =0
,那么情节将如下所示:
< img src =https://i.stack.imgur.com/yrgeW.pngalt =在这里输入图片描述>
I've been trying to recreate this post on a combination of stacked bar/area plot. I have some problems with missing values though.
Here's my data: https://www.dropbox.com/sh/pnkspwnn1qslm6u/JapTKCwqMS
What I run is;
wa=read.table('wa_class.txt', sep="", header=F, na.string="0")
names(wa)=c("Class","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
wam=melt(wa)
wam$variablen=as.numeric(wam$variable)
How it looks like
> head(wam)
Class variable value variablen
1 Actinobacteria Jan 38.115163 1
2 Flavobacteria Jan NA 1
3 Sphingobacteria Jan 3.640469 1
4 Alphaproteobacteria Jan 13.631663 1
5 Betaproteobacteria_b28 Jan 3.718671 1
6 Betaproteobacteria Jan 14.732354 1
ggplot(na.omit(wam[,c("Class","value","variablen")]), aes(wam,x=variablen, y=value, fill=Class)) + geom_area(color="black") + geom_linerange(aes(ymax=value), position="stack") + scale_x_continuous(breaks=1:max(wam$variablen)) + labs(title="Water", x="Month", y="Relative abundance (%)")
...so I have tried to correct for the missing values with use na.omit on the variables I plot. However, I get layers in the plot which e.g. is overriding each other (see dropbox folder).
I found this post (see dropbox folder) which corrected for it, but seemed only to have one. And I couldn't reproduce it since the link to the data is dead.
Any help would really be appreciated!
Thanks,
Jo
One solution is to read zeros as zero values. If you don't use na.string="0"
, the plot will look like this:
这篇关于使用ggplot2更正Stacked区域图中的缺失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!