有人知道如何減少尺寸圖例的鍵之間的距離嗎?
無需調整其他(顏色)圖例的距離。

順便說一句,縮寫代碼如下所示:
data %>%
ggplot( aes(x=x, y=y, size=z, color=c, alpha=d))
geom_point()
scale_size_area(name="Cumulative excess deaths (thousands)",
max_size = 70, limits=c(NA, 10000),
breaks=c(1, 10, 100,500,1000, 5000))
geom_abline(slope=1, intercept = 0, size=0.2)
scale_color_manual(name="World Bank Income group")
scale_alpha_manual(values=c(0.55,0.2))
labs(...)
theme_bw()
theme(
plot.margin = margin(0.5, 0.2, 0.5, 0.5, "cm"),
plot.background = element_rect(size = 1),
plot.caption.position="plot",
legend.position="right",
legend.box.margin = margin(2,0,0,0, "cm"),
legend.title=element_text(size=8,color="black", hjust=0),
legend.text =element_text(size=8,color="black"),
legend.spacing = unit(-0.5, "cm"),
legend.key.size = unit(1,"line"),
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
panel.border = element_blank())
coord_cartesian(clip = 'off')
guides(alpha=FALSE)
guides(size=guide_legend(override.aes=list(shape=1),order=1),
color = guide_legend(override.aes = list(size=6, alpha=0.55),
order=2))
uj5u.com熱心網友回復:
雖然沒有真實資料很難確定,但下面的 3 個示例(使用虛構資料和最少的代碼)向我表明,導致問題的原因是scale_size_area更大max_size和更小(第二個示例)。limit
相比之下,第一個和第三個例子看起來很合理。
library(tidyverse)
df <- tribble(
~x, ~y, ~z, ~c,
200, 250, 1, 1,
300, 270, 20, 1,
400, 300, 500, 2,
600, 325, 50000, 3
)
# Scale_size with trans
df |>
mutate(c = factor(c)) |>
ggplot(aes(x = x, y = y, size = z, color = c))
geom_point()
scale_size_continuous(
name = "Cumulative excess\ndeaths (thousands)",
range = c(0, 20),
trans = "sqrt",
breaks = c(1, 10, 100, 1000, 5000)
)

# Scale_size_area with large max_size and smaller limit
df |>
mutate(c = factor(c)) |>
ggplot(aes(x = x, y = y, size = z, color = c))
geom_point()
scale_size_area(
name = "Cumulative excess\ndeaths (thousands)",
max_size = 70, limits = c(NA, 10000),
breaks = c(1, 10, 100, 500, 1000, 5000)
)

# Scale_size_area with smaller max_size and larger limit
df |>
mutate(c = factor(c)) |>
ggplot(aes(x = x, y = y, size = z, color = c))
geom_point()
scale_size_area(
name = "Cumulative excess\ndeaths (thousands)",
max_size = 30, limits = c(NA, 50000),
breaks = c(1, 10, 100, 500, 1000, 5000)
)

由reprex 包于 2022-06-16 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/493130.html
