0

My code:

plot1 <- qplot(price, property_type, data = lings, colour = host_is_superhost)

+theme_classic()

The result is:

I cannot see the price. How do I change the range of the X-axis?

Mdallal
  • 31
  • 4
  • 1
    You can check [here](https://stackoverflow.com/questions/3606697/how-to-set-limits-for-axes-in-ggplot2-r-plots) – akrun Dec 23 '20 at 18:10
  • It looks as if your `price` might be `character` or `factor`, so the axis is "discrete" instead of "continuous". If that's the case, and you *intend* for `price` to be a "number" (`numeric` or `integer`), then consider converting it with `as.numeric` or similar. – r2evans Dec 23 '20 at 18:19
  • btw, please remove the [tag:rstudio] tag, this has nothing to do with the IDE – r2evans Dec 23 '20 at 18:20
  • Does this answer your question? [How to set limits for axes in ggplot2 R plots?](https://stackoverflow.com/questions/3606697/how-to-set-limits-for-axes-in-ggplot2-r-plots) – tjebo Dec 23 '20 at 18:41

1 Answers1

1

You should be able to add the additional element by adding + xlim() to your plot:

plot1 <- qplot(price, property_type, data = listings, colour = host_is_superhost) + 
theme_classic() + xlim(50, 100)

Where you would change the numbers 50 (lower limit) and 100 (upper limit) of xlim(50, 100) to whatever you need.

I would also point out that the price field on the x-axis has a problem with the labels, which makes me think the data is in the incorrect character or factor data type rather than a numeric type. If that is the case, before plotting your data you might want to include this line of code:

listings$price <- as.numeric(listings$price)
Ricky
  • 1,005
  • 1
  • 12
  • 15