Help understanding how to make a bar chart using ggplot2

Posted by celenius on Stack Overflow See other posts from Stack Overflow or by celenius
Published on 2011-01-01T17:25:11Z Indexed on 2011/01/02 17:53 UTC
Read the original article Hit count: 347

Filed under:
|

I'm trying to use the bar_geom function of ggplot2, but I can't understand how to use it. I've made a small sample of my code to show what I am trying to do:

library(ggplot2)

# sample data
sampleData = data.frame( 
 v1=c('a','b','c','d','e', 'f','g', 'h', 'i','j'), 
 v2=c(1:10)     
)    
sampleData$Names = data.frame( Names = paste(sampleData$v1, sampleData$v2, sep="") )    
sampleData$Values = c(1:10)

# make plot
x = sampleData$Values
y = sampleData$Names 

qplot(      
    x, y, data = sampleData,
    geom="bar"  
)

I want sampleData$Names to be on the x-axis of my graph, labeling each bar and and sampleData$Values to scale the bar height. I want the y-axis to be specified as a range. I realize that I don't understand how ggplot2 functions as this small example does not work, yet my other example is generating a plot but I cannot specify a y-range as it considers the variables to be categorical.

© Stack Overflow or respective owner

Related posts about r

    Related posts about ggplot2