How do I 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 have 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
You may notice that we sometimes reference 'ggplot2' and sometimes 'ggplot'. To clarify, 'ggplot2' is the name of the most recent version of the package. However, any time we call the function itself, it's just called 'ggplot'.
To draw a plot from two vectors in R, where one vector represents data points along X axis, and the other vector represents data points along Y axis, call plot() function and pass the two vectors as arguments to the plot() function.
ggplot2 [library(ggplot2)] ) is a plotting library for R developed by Hadley Wickham, based on Leland Wilkinson's landmark book The Grammar of Graphics ["gg" stands for Grammar of Graphics].
geom_bar()
needs also x
values to make the barplot. One workaround would be to provide just sequence of numbers that are the same lenght as value
.
ggplot(pValues_Both.m, aes(x=seq_along(value),y=value)) +
geom_bar(stat="identity")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With