[英]How to remove extra column in facet_wrap plot with ggplot2?
我正在尝试使用带有不平衡分组数据的facet_wrap
生成一个分面图,并且它提供了一个带有额外空白轴列的图。
这是一个示例代码:
library(ggplot2)
name <- c(factor(letters[1:4]),factor(LETTERS[1:3]))
room <- rep(c('A','B'),c(4,3))
goal <- c(rnorm(7,mean=60,sd=10))
test <- data.frame(name,goal,room)
test %>% ggplot(aes(name, goal))+
facet_wrap(~factor(room))+
geom_bar(stat = "identity")
'scales="free"'方式:自动设置,可以手动设置吗?
facetted_pos_scales
在ggh4x
通过@teunbrand开发sovled问题,thnaks! 这是补充代码:
library(ggh4x)
scales <- list(
scale_y_continuous(limits = c(0, 100)),
scale_y_continuous(limits = c(0, 80))
)
test %>% ggplot(aes(name, goal))+
facet_wrap(~factor(room), scales="free")+
geom_bar(stat = "identity")+
facetted_pos_scales(y=scales)
更新 op 评论:这有帮助吗:您可以使用coord_cartesian(ylim = c(0, 90))
来设置ylim
:
test %>% ggplot(aes(name, goal))+
geom_bar(stat = "identity")+
coord_cartesian(ylim = c(0, 100)) +
facet_wrap(~factor(room), scales="free")
使用scales="free"
而不是scales="free_x"
library(ggplot2)
name <- c(factor(letters[1:4]),factor(LETTERS[1:3]))
room <- rep(c('A','B'),c(4,3))
goal <- c(rnorm(7,mean=60,sd=10))
test <- data.frame(name,goal,room)
test %>% ggplot(aes(name, goal))+
facet_wrap(~factor(room), scales="free")+
geom_bar(stat = "identity")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.