Plot a vector of y-values ​​in ggplot

How to plot a vector of y values ​​in ggplot2?

 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)

      

I've tried the following:

 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


source to share


2 answers


geom_bar()

it also requires a value x

to create the line art. One way would be to provide only a sequence of numbers that are the same length as value

.



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

      

+3


source


It's also ggplot qplot

1-liner without the need to create a dataframe (it does this for you), but the same basic principle as Didzis':

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

      



enter image description here

+4


source







All Articles