使用facet_zoom放大分类图?

问题描述 投票:0回答:1

当我尝试this时:

# 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)

问题

如何放大分类数据?

r ggplot2 ggforce
1个回答
0
投票

我能够使用scale_x_discrete或仅xlim放大分类数据。coord_cartesian似乎期望使用数值/数学值,这对于连续数据非常有用。

这是一个非常基本的示例,希望对您有所帮助:{#basic mtcars数据图,x上具有汽车名称,y上具有mpg,大小=马力ggplot(mtcars,aes(x =行名(mtcars),y = mpg,大小= hp))+ geom_point()+ geom_smooth()+

#“放大”以仅看到这两辆车scale_x_discrete(limits = c(“ Datsun 710”,“ Dodge Challenger”))+

#OR xlim(c(“ Datsun 710”,“道奇挑战者”))}

© www.soinside.com 2019 - 2024. All rights reserved.