0

I've tried following the instructions for question 28557393 but they don't seem to work for me. My data (converted to what I think is a long table)
I have tried this code

ggplot(table_long, aes(x=Year, y=ktoe, fill=factor(energy_type))) +  
geom_col()

which looks like This.

or this

ggplot(table_long, aes(x = Year, y = ktoe, fill=energy_type)) +  
geom_bar(stat='identity')

which looks like this here. What am I doing wrong? I have some hope my data is correctly form as

table_long %>%
  ggplot() +
  geom_point(aes(x=Year, y=ktoe, col=energy_type))

Looks roughly like I want the bar chart to look like: geom plot

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • It looks like your variable "ktoe" is a factor or character type and not numeric. Try converting to numeric with `y=as.numeric(ktoe)` in the `aes` definition and see if that works. – Dave2e Apr 23 '20 at 14:33
  • it will be easier to answer this question if you provide a reproducible example, see [here0(https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for how to make a reproducible example – yang Apr 23 '20 at 14:33
  • 1
    what do you get with `str(table_long)`? Similar issue as @Dave2e referred to, but wondering about Year. – markhogue Apr 23 '20 at 14:34
  • @markhogue > str(table_long) Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 392 obs. of 3 variables: $ Year : num 1970 1971 1972 1973 1974 ... $ energy_type: chr "Coal" "Coal" "Coal" "Coal" ... $ ktoe : chr "14242" "12164" "10602" "10565" ... – Handschuhe Apr 23 '20 at 15:57
  • @Dave2e I think you have cracked the most basic problem, it plots something much more like I was expecting now! Thanks for you help. I can't see how to upvote answers, maybe I'm too new? – Handschuhe Apr 23 '20 at 15:59
  • @Handschuhe, I am glad you were able to solve your problem. This is a common problem trying to plot the wrong data type. I am going to flag this question for closure since this is such a common problem and many posted solutions. – Dave2e Apr 23 '20 at 16:04

0 Answers0