我正在尝试在 facet_grid 和 facet_wrap 之间生成一种“混合”布局的图:
例子:
library(reshape2)
library(ggplot2)
data(diamonds)
# sample and reshape diamond dataset
diamonds_l <- melt(diamonds[sample(1:nrow(diamonds), 200),
c("cut", "depth", "table", "price", "x")],
id.vars = c("cut","x"))
这是我想要的情节安排(列和深度的质量,表格,价格作为行)
ggplot( diamonds_l, aes( x = value, y = x, colour= cut))+
geom_point( ) +
facet_wrap( variable ~ cut, scales = "free_x", nrow=3)
但是,我更喜欢 facet_grid 设计(每列/行只有一个标题)但 scales = "free_x" 在此布局中不起作用
ggplot( diamonds_l, aes( x = value, y = x, colour= cut))+
geom_point( ) +
facet_grid(variable ~ cut, scales = "free_x")
它在这里工作,但这不是我想要的安排(质量作为行)
ggplot( diamonds_l, aes( x = value, y = x, colour= cut))+
geom_point( ) +
facet_grid(cut ~ variable, scales = "free_x")
我明白为什么它不起作用,但我想知道是否有解决方法?
谢谢!
费边