R ggplot条形图中的额外条形图
我的数据是R ggplot条形图中的额外条形图,r,ggplot2,R,Ggplot2,我的数据是 > data width variable value 1 200 mappedEnsemblTx 110 2 400 mappedEnsemblTx 392 3 600 mappedEnsemblTx 1055 4 800 mappedEnsemblTx 2615 5 1000 mappedEnsemblTx 5201 101 200 UnmappedEnsemblTx 3
> data
width variable value
1 200 mappedEnsemblTx 110
2 400 mappedEnsemblTx 392
3 600 mappedEnsemblTx 1055
4 800 mappedEnsemblTx 2615
5 1000 mappedEnsemblTx 5201
101 200 UnmappedEnsemblTx 3927
102 400 UnmappedEnsemblTx 5175
103 600 UnmappedEnsemblTx 3220
104 800 UnmappedEnsemblTx 4856
105 1000 UnmappedEnsemblTx 7130
当我画这幅图时,我看到的不是两条,而是三条,或者可能是四条。
最低代码如下所示:
library(ggplot2)
g = ggplot(dat.melt,aes(x=factor(width),y=value,fill=variable), format(scientific=FALSE))
g = g + geom_bar(stat='identity',position='dodge')
g <- g + theme_bw()
g = g + opts(axis.text.x=theme_text(angle=-90, hjust=0, size = 16), axis.text.y=theme_text(size=16))
g <- g + opts(axis.title.x = theme_text(size=18), axis.title.y = theme_text(size=18, angle=90) )
g = g + scale_x_discrete('Total widths of the Ensembl Transcripts') + scale_y_continuous(name = 'Count')
g = g + coord_cartesian(ylim = c(0,7000))
非常感谢
data.melt <- structure(list(width = c(200L, 400L, 600L, 800L, 1000L, 200L,
400L, 600L, 800L, 1000L), variable = structure(c(1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c("mappedEnsemblTx", "UnmappedEnsemblTx"
), class = "factor"), value = c(110L, 392L, 1055L, 2615L, 5201L,
3927L, 5175L, 3220L, 4856L, 7130L)), .Names = c("width", "variable",
"value"), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "101", "102", "103", "104", "105"))
与
dat.melt是否意味着是data.melt?如果不是,那么在最小代码中的任何地方都没有出现数据是错误的吗?我对R和ggplot都一无所知,但为什么只需要两个条呢?在x轴上放置了宽度,有五个不同的宽度值。你不应该得到五个酒吧吗?或者确实是十个,每个x位置两个,通过位置class='dodge'彼此移动到一边?你能更具体地说一下你期望看到什么吗?当然你可以说两个以上的小节,你实际看到的肯定可以说三个以上或者可能是四个小节。我很抱歉弄错了。data.melt需要是data dat.melt是data.melt吗?如果不是,那么在最小代码中的任何地方都没有出现数据是错误的吗?我对R和ggplot都一无所知,但为什么只需要两个条呢?在x轴上放置了宽度,有五个不同的宽度值。你不应该得到五个酒吧吗?或者确实是十个,每个x位置两个,通过位置class='dodge'彼此移动到一边?你能更具体地说一下你期望看到什么吗?当然你可以说两个以上的小节,你实际看到的肯定可以说三个以上或者可能是四个小节。我很抱歉弄错了。data.melt需要数据谢谢galvin,我的输入数据有问题。谢谢galvin,我的输入数据有问题。
g <- ggplot(data.melt,aes(x=factor(width),y=value,fill=variable),
format(scientific=FALSE))
g <- g + geom_bar(stat='identity',position='dodge')
g <- g + theme_bw()
g <- g + opts(axis.text.x=theme_text(angle=-90, hjust=0, size = 16),
axis.text.y=theme_text(size=16))
g <- g + opts(axis.title.x = theme_text(size=18),
axis.title.y = theme_text(size=18, angle=90) )
g <- g + scale_x_discrete('Total widths of the Ensembl Transcripts') +
scale_y_continuous(name = 'Count')
g <- g + coord_cartesian(ylim = c(0,7000))
g
R> sessionInfo()
R version 2.15.0 Patched (2012-04-16 r59049)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_GB.utf8 LC_NUMERIC=C
[3] LC_TIME=en_GB.utf8 LC_COLLATE=en_GB.utf8
[5] LC_MONETARY=en_GB.utf8 LC_MESSAGES=en_GB.utf8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_0.9.0
loaded via a namespace (and not attached):
[1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 grid_2.15.0
[5] MASS_7.3-17 memoise_0.1 munsell_0.3 plyr_1.7.1
[9] proto_0.3-9.2 RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.2.0
[13] stringr_0.6 tools_2.15.0