Query using geom_bar() of ggplot2 - R

10,694

Rolling @joran's comments into an answer:

ggplot(mapDF, aes(x=var, y=approvals)) + geom_bar(stat="identity")
Share:
10,694

Related videos on Youtube

name_masked
Author by

name_masked

Primary programming languages: Java, C Inclined on learning: Python, Android app Development

Updated on September 14, 2022

Comments

  • name_masked
    name_masked over 1 year

    I have a similar data frame as follows:

    mapDF <- structure(list(var = c(11L, 3L, 4L, 15L, 19L, 17L, 1L), approvals = c(10.5233545765422, 
    67.9809421770218, 9.66394835013545, 2.93736399165075, 3.36787205222721, 
    4.0168261757783, 1.50969267664431)), .Names = c("var", "approvals"
    ), row.names = c(NA, -7L), class = "data.frame")
    

    When I try creating a bar graph using the data frame above using:

    gplot <- ggplot(mapDF, aes(x= mapDF[1], y= mapDF[2])) + geom_bar()
    

    .. I get the following messages with nothing showing up in the 'Plots' section of RStudio:

    Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous
    Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous
    Error: stat_bin requires the following missing aesthetics: x
    

    Can anyone please point out my error?

    • joran
      joran over 11 years
      Ever notice how in all the ggplot code you've ever seen people map aesthetics inside aes using the name of the column...? :)
    • joran
      joran
      (And you will want stat = "identity" inside geom_bar.)