0

I am making a chart in ggplot to show the amount of crime that occurs in a certain year. The graph comes out well, but the x-axis values aren't showing. I then try manually plotting the values using scale_x_continuous and scale_x_discrete.

With scale_x_continuous(limits=c(0,500000)) the following error occurs:

Error: Discrete value supplied to continuous scale

Here is the code I am using:

 ggplot(london2012,aes(london2012$Crime, london2012$X2012)) +
 geom_col(aes(fill=as.factor(london2012$Crime)), show.legend = FALSE) +
 coord_flip() + theme_classic() + theme(axis.text = element_text(face = 
 "bold", color = "black")) +
 theme( axis.title.x=element_blank(),
        axis.title.y =element_blank())

enter image description here

I am using the same code for another dataset and it comes out correctly

 ggplot(SouthAfricanCrimeWC,aes(SouthAfricanCrimeWC$Category, SouthAfricanCrimeWC$X2010)) +
 geom_col(aes(fill=as.factor(SouthAfricanCrimeWC$Category)), show.legend = FALSE) +
 coord_flip() + theme_classic() + theme(axis.text = element_text(face = "bold",color = "black")) +
 theme(axis.title.x=element_blank(),
    axis.title.y=element_blank())

enter image description here

Any suggestions that may help it work?

lmo
  • 37,904
  • 9
  • 56
  • 69
DylanHig
  • 29
  • 4
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions – MrFlick Apr 16 '18 at 17:13
  • Thank you, I will look into producing one asap! :) – DylanHig Apr 16 '18 at 17:21
  • 1
    This looks like it could be a case of `X2012` being coded as a factor rather than as numeric (run `class(london2012$X2012)` to check). Also, you should remove all instances of `london2012$`. Only bare column names should be used inside `aes`. – eipi10 Apr 16 '18 at 17:22
  • Thanks so much eipi10. It was indeed a factor, I just noticed that also. It works perfect now :D – DylanHig Apr 16 '18 at 17:24

0 Answers0