我有一個如下所示的情節。但是,正如您所見,面 4 只有 1 個樣本,但垂直大小等于面 6,它有 4 個樣本;這使得情節看起來很奇怪,因為它變得很厚。我現在不能使用 face_grid ( facet_grid( cyl~. , scales = "free", space="free" )) 因為標簽會放在一邊,但我真正想要的是像 facet_wrap 一樣把標簽放在上面,如下圖所示。有沒有辦法解決?謝謝。
temp = head ( mtcars )
temp$car = row.names ( temp )
ggplot( temp , aes(x=car , y=hp, fill=vs ))
geom_bar(stat = 'identity', position = 'stack')
theme_bw()
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
coord_flip()
scale_y_continuous(expand = expansion(mult = c(0, .1)))
facet_wrap( ~cyl , ncol=1, scales = "free" )

uj5u.com熱心網友回復:
不確定你是否想要這個。如果是這樣,您可以使用facet_colfrom the package ggforce,它允許您在單個列中使用 facet 并洗掉 facet ratio(space引數)。
library(tidyverse)
library(ggforce)
temp = head (mtcars)
temp$car = row.names(temp)
ggplot(temp, aes(x = car , y = hp, fill = vs))
geom_bar(stat = 'identity', position = 'stack')
theme_bw()
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
panel.background = element_blank(), axis.line = element_line(colour = "black"))
coord_flip()
scale_y_continuous(expand = expansion(mult = c(0, .1)))
ggforce::facet_col(cyl ~ ., scales = "free", space = "free")

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/427676.html
下一篇:按日期順序繪制資料
