在ggplot中绘制y值的向量

时间:2014-09-13 14:55:56

标签: r plot ggplot2

如何在ggplot2中绘制y值的向量?

 pValues_Both <- c(0.004079,0.4392,0.6882,0.02053,0.4849,0.4938,0.3379,0.8408,0.07067,0.6603,0.2547,0.8692,0.8946,0.0696,0.6206,0.9559,0.9119,0.5162,:0.2469,0.1582)

我尝试了以下内容:

 pValues_Both.m <- melt(pValues_Both)

ggplot(pValues_Both.m, aes(y=value)) + geom_bar(stat="identity")

Error in exists(name, envir = env, mode = mode) : 
argument "env" is missing, with no default

3 个答案:

答案 0 :(得分:4)

它也是一个ggplot qplot 1-liner,不需要预先制作数据框(它适合你),但与Didzis相同的基本原则是:< / p>

qplot(x=1:length(pValues_Both), y=pValues_Both, geom="bar", 
    stat="identity", xlab="", ylab="", main="pValues_Both")

enter image description here

答案 1 :(得分:3)

geom_bar()还需要x值来制作条形图。一种解决方法是提供与value相同长度的数字序列。

ggplot(pValues_Both.m, aes(x=seq_along(value),y=value)) + 
    geom_bar(stat="identity")

答案 2 :(得分:0)

qplot 如果未提供,则为您创建数据帧。您想要的图在 ggplot 中称为 col 图,因此:

pVals = c(.0041,.4392,.6882,.02053,.4849,.4938,.3379,.8408,.07067,.6603,.2547,.8692,.8946,.0696,.6206,.9559,.9119,.5162,.2469,.1582)

qplot(x = 1:20, y = pVals, geom = "col")