hadley / r4ds

R for data science: a book
http://r4ds.hadley.nz
Other
4.59k stars 4.22k forks source link

in e.g. code why is scale_x_continuous used for a categorical var drv #1547

Closed soumyakde closed 1 year ago

soumyakde commented 1 year ago

Hi, In the code (in sec. 12.4.5 - zooming), you have used:

Left

ggplot(mpg, aes(x = displ, y = hwy)) + geom_point(aes(color = drv)) + geom_smooth() + scale_x_continuous(limits = c(5, 6)) + # drv is a categorical #var scale_y_continuous(limits = c(10, 25)) Whereas, if I use the scale_x_discrete, the plot is significantly different, why? I am a novice, hence thought I ask. Which plot is accurate? ggplot(mpg, aes(x = displ, y = hwy)) + geom_point(aes(color = drv)) + geom_smooth() + scale_x_discrete(limits = c(5, 6)) + scale_y_continuous(limits = c(10, 25))

soumyakde commented 1 year ago

Aplogize, understood my mistake, closing the issue.