我有一個資料框設定如下:
| 地區 | 次區域 | 行進 | 四月 | 可能 |
|---|---|---|---|---|
| 一種 | A1 | 9.2 | 7.9 | 8.0 |
| 一種 | A2 | 8.9 | 8.5 | 8.0 |
| 一種 | A3 | 9.5 | 8.5 | 8.4 |
| 乙 | B1 | 9.1 | 8.7 | 8.5 |
| 乙 | B2 | 9.9 | 8.0 | 7.7 |
| C | C1 | 8.7 | 8.0 | 8.2 |
| C | C2 | 9.3 | 8.0 | 8.4 |
| C | C3 | 9.1 | 8.3 | 8.5 |
我已經融化了資料框,所以它的格式如下:
| 地區 | 次區域 | 多變的 | 價值 |
|---|
我正在嘗試創建一個帶有 facet wrap/grid 的 ggplot boxplot,以便輸出包含每個區域的面板,并且每個面板內是每個子區域的 boxplot。我試過下面的代碼,但它不是所需的輸出:
p<- Name_SR %>%
ggplot(aes(value, sub_region))
geom_boxplot()
labs(title="",
subtitle ="
",
x="Percentage Difference",
y = "Sub-Region")
facet_wrap(~Region)
theme(panel.grid = element_blank(),
plot.margin=unit(c(1,6,1,1),"cm"),
plot.title = element_text(size=12),
plot.subtitle = element_text(size=10),
axis.title = element_text(size = 10))
q<- p theme(axis.text = element_text(size=8))
請問有人可以幫助我嗎?
uj5u.com熱心網友回復:
我認為這應該可以滿足您的要求,如果Name_SR您融化了 df ...
Name_SR %>%
ggplot(aes(x = sub_region, y = value)) #yours are the wrong way round
geom_boxplot()
facet_wrap(~Region, scales = "free_x") #free_x removes irrelevant subregions
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/365020.html
上一篇:在構建期間不執行測驗
