7
我正在試圖在ggplot2中繪製水平箱圖,只能使用coord_flip()進行繪圖。我也試圖垂直放置箱形圖以將某些組合在一起。我已經閱讀過這種類型的建議,但這與coord_flip()不兼容,正如我們在這裏看到的:ggplot2: boxplot with facet_grid and free scale。所以我想知道是否可以使用空白級別來創建空格。以下是我已經設法到目前爲止做:在ggplot2中定位水平箱圖
d <- diamonds
library("ggplot2")
levels(d$cut) <- list(A="Fair", B="Good", "-", C="Very Good", D="Ideal", E="Premium")
p = ggplot(d, aes(x=cut, y=depth))
p +
geom_boxplot(color="black", size=0.2) +
theme_bw() +
scale_x_discrete(breaks = c("A", "B", "-", "C", "D", "E"), drop=FALSE) +
coord_flip()
ph = 2.75
pw = 4
ggsave("plot.png", height=ph, width=pw)
正如你可以看到,如果我創建一個空白的水平「 - 」它,並將其納入scale_x_discrete(),然後以某種方式得到了一個空白行。問題是我只能添加一個空格。有沒有人有任何想法如何在這些水平方塊圖之間添加空格?