1

当我尝试这样做时:

# loading needed libraries
library(ggplot2)
library(ggforce)

# selecting variables to display
names <- as.vector(unique(mpg$manufacturer))
selected.names <- names[4:11]

# zooming in on the axes
ggplot(mpg, aes(x = manufacturer, y = class)) +
  geom_jitter() +
  facet_zoom(x = manufacturer %in% selected.names)

我没有得到放大的情节,而是

错误:facet_zoom 不支持缩放离散比例

(我有一个更详细的真实示例,但这很适合作为 MRE)

问题

如何放大分类数据?

4

1 回答 1

0

我能够使用scale_x_discrete或仅放大分类数据xlim。Coord_cartesian 似乎期望一个数字/数学值,这对连续数据很有用。

这是一个非常基本的示例:

# basic mtcars data plot with car names on x and mpg on y, size = horsepower
library (ggplot2)
ggplot(mtcars, aes(x = rownames(mtcars), y = mpg, size = hp)) + 
  geom_point() + 
  geom_smooth() +
# to 'zoom in' to see only these two cars
  scale_x_discrete(limits = c("Datsun 710", "Dodge Challenger")) 
# OR xlim(c("Datsun 710", "Dodge Challenger"))
于 2020-05-10T01:33:38.387 回答