How to zoom in on a specific range of values for a categorical variable in ggplot2?
问题 I just want to zoom in on the x-axis between the values ford and nissan in the mpg dataframe. Package used: tidyverse But I am getting the following error when using the coord_cartesian() function: p<-ggplot(mpg,aes(x=manufacturer,y=class)) p+geom_point()+ + coord_cartesian(xlim = c('ford','nissan')) Error in +coord_cartesian(xlim = c("ford", "nissan")) : invalid argument to unary operator 回答1: You can use a function for contextual zoom from ggforce package ( facet_zoom ) to achieve this: #