[英]Change y-axis center in ggplot
無論如何,在ggplot中將y軸的“中心”移動到1而不是0? 我有比率數據,所以我試圖以一種方式將值可視化,使其值大於或小於1,而不是大於或小於0。到目前為止,我只是從數據中減去1,並將其定為0左右,但是我未能成功重新標記y軸以使其反映我想要的數字。
chi_ratios_plot <- ggplot(data=chi_ratios, aes(x = metric, y =ratio2, fill=coral_cover))+
geom_bar(stat="identity", position="dodge")+
theme_classic()+
coord_flip()
使用手動移動的比率值,您可以通過為scale_y_continuous
提供labels
參數並將其回退到1來修正其標簽:
chi_ratios = expand.grid(
metric = c("A", "B", "C"),
coral_cover = c("Low", "Med", "High")
) %>%
# ratio: actual ratios
# ratio2: shifted so they're centered at 0
mutate(ratio = rnorm(n(), mean = 1, sd = 2),
ratio2 = ratio - 1)
ggplot(data=chi_ratios, aes(x = metric, y = ratio2, fill = coral_cover)) +
geom_col(position="dodge") +
scale_y_continuous(labels = function(breaks) { breaks + 1}) +
theme_classic() +
coord_flip()
我看不到任何選項可以覆蓋geom_bar()
或geom_col()
的0基線,並且通過geom_bar()
實現相同的操作很geom_rect()
,因此這似乎是最簡單的選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.