r - Code isn't plotting level 0 of a factor in ggplot's geom_bar() -
my final plot doesn't show 0 level factor a.
header data:
month b mayo 20 6.9 mayo 16 16.3 mayo 14 19.8 mayo 12 12.6 mayo 9 19.5 mayo 8 65.4 mayo 18 11.7 mayo 17 22.8 mayo 15 34.3 mayo 13 36.9 mayo 11 43.7 mayo 10 21.6 mayo 21 20.9 mayo 7 7.3 mayo 22 32.3 mayo 19 17.8 mayo 0 96.0
structure of data.frame:
'data.frame': 17 obs. of 3 variables: $ month : chr "mayo" "mayo" "mayo" "mayo" ... $ : factor w/ 18 levels "0","7","8","9",..: 15 11 9 7 4 3 13 12 10 8 ... $ b: num 6.9 16.3 19.8 12.6 19.5 65.4 11.7 22.8 34.3 36.9 ...
my r code ggplotting:
ggplot(data,aes(x = a, y = b)) + geom_bar(stat="identity",size=1.5,colour = "black",fill="green")
update
it has been problem r code. level 0 included in month == "mayo", not month =="abril" (included in full data).
indeed, doesn't show 0 level:
ggplot(data[data$month=="abril",],aes(x = a, y = b)) + geom_bar(stat="identity",size=1.5,colour = "black",fill="green")
thanks
seems work me
data <- data.frame(month=rep('mayo',17), a=factor(c(20,16,14,12,9,8,18,17,15,13,11,10,21,7,22,19,0)), b=c(6.9,16.3,19.8,12.6,19.5,65.4,11.7,22.8,34.3,36.9,43.7,21.6,20.9,7.3,32.3,17.8,96.0), stringsasfactors = f) ggplot(data,aes(x = a, y = b)) + geom_bar(stat="identity",size=1.5,colour = "black",fill="green") str(data)
structure of data.frame
'data.frame': 17 obs. of 3 variables: $ month: chr "mayo" "mayo" "mayo" "mayo" ... $ : factor w/ 17 levels "0","7","8","9",..: 15 11 9 7 4 3 13 12 10 8 ... $ b : num 6.9 16.3 19.8 12.6 19.5 65.4 11.7 22.8 34.3 36.9 ...
there's structure of data.frame.. in case posted have 18 factor levels.. 17 observations?
Comments
Post a Comment