I am trying to generate a facet plot with facet_wrap
with an unbalanced grouped data, and it provided a plot with extra blank axis column.
Like the paragraph showed, I want to generate a plot without the rightmost axis column.
Here is an example code:
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"' way: automatic set, can it be set manually?
facetted_pos_scales
in ggh4x
developed by @teunbrand sovled the problem, thnaks! Here is the supplementary code:
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)
Update on comment of op: Does this help: You can use coord_cartesian(ylim = c(0, 90))
to set the ylim
:
test %>% ggplot(aes(name, goal))+
geom_bar(stat = "identity")+
coord_cartesian(ylim = c(0, 100)) +
facet_wrap(~factor(room), scales="free")
Use scales="free"
instead of 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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.