2012-10-15 18 views
5

Ho una trama di dati simile come segue:Query utilizzando geom_bar() di ggplot2 - R

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") 

Quando provo creando un grafico a barre utilizzando il frame di dati sopra utilizzando:

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

. . ottengo i seguenti messaggi con nulla presentandosi nella sezione 'piazzole di 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 

Qualcuno può indicare il mio errore?

+5

Avete mai notato come le persone in tutto il codice ggplot che abbiate mai visto mappa estetica all'interno 'aes' utilizzando il _NAME_ della colonna ...? :) – joran

+1

(E vorrete 'stat =" identità "' dentro 'geom_bar'.) – joran

+0

@joran: darnnn !!! ... grazie –

risposta

8

commenti rotolamento @ di Joran in una risposta:

ggplot(mapDF, aes(x=var, y=approvals)) + geom_bar(stat="identity") 
+0

+1 per dare un esempio. Il sarcasmo di joran era un po 'spinto per questo. – badgley

Problemi correlati