Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a vector of y-values in ggplot?

Tags:

plot

r

ggplot2

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
like image 687
BioMan Avatar asked Sep 13 '14 14:09

BioMan


People also ask

What is the difference between ggplot and ggplot2?

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'.

How do I plot two vectors in R?

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.

What does the GG in ggplot mean?

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].


1 Answers

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")
like image 99
Didzis Elferts Avatar answered Oct 13 '22 19:10

Didzis Elferts