如何删除图表中的额外空间?scale_y_continuous也无法正常工作。
ggplot(data = data_div_1, aes(x = Initiative, y = Record, fill = Type)) +
geom_bar(stat = "identity") +
geom_hline(yintercept = 0, size = 2, colour = 'gray50') +
scale_x_discrete(limits = rev(data_div_1$Initiative)) +
scale_y_continuous(breaks = breaks_values, labels = abs(breaks_values)) +
coord_flip() +
theme_economist_white(gray_bg = FALSE) +
scale_fill_manual(values = c("#1A476F", "#2D6D66")) +
labs(title = "Theme 1", x = "", y = "", fill = "") +
theme(legend.position = "none")
break_values
-15 -10 -5 0 5 10 15我必须为七个对象重新制作这个发散图,所有对象都有相似的输出。

如果移除scale_x_discrete(),则会显示正确配合但反转的标签。

dput(data_div_1)
structure(list(Theme = c("Theme 1", "Theme 1", "Theme 1", "Theme 1",
"Theme 1", "Theme 1", "Theme 1", "Theme 1", "Theme 1", "Theme 1"
), Initiative = c("Initiative 1", "Initiative 2", "Initiative 3",
"Initiative 4", "Initiative 5", "Initiative 1", "Initiative 2",
"Initiative 3", "Initiative 4", "Initiative 5"), Type = c("Desirability",
"Desirability", "Desirability", "Desirability", "Desirability",
"Feasibility", "Feasibility", "Feasibility", "Feasibility", "Feasibility"
), Record = c(10, 9.5, 11, 11.5, 7.5, -9, -8.5, -9, -8.5, -8.5
), Label = c("Theme 1: Initiative 1", "Theme 1: Initiative 2",
"Theme 1: Initiative 3", "Theme 1: Initiative 4", "Theme 1: Initiative 5",
"Theme 1: Initiative 1", "Theme 1: Initiative 2", "Theme 1: Initiative 3",
"Theme 1: Initiative 4", "Theme 1: Initiative 5")), class = "data.frame", row.names = c(NA,
-10L))发布于 2021-03-20 16:13:19
这可以通过rev(unique(...))实现,如下所示:
library(ggplot2)
library(ggthemes)
breaks_values <- c(-15L, -10L, -5L, 0L, 5L, 10L, 15L)
ggplot(data = data_div_1, aes(x = Initiative, y = Record, fill = Type)) +
geom_bar(stat = "identity") +
geom_hline(yintercept = 0, size = 2, colour = 'gray50') +
scale_x_discrete(limits = rev(unique(data_div_1$Initiative))) +
scale_y_continuous(breaks = breaks_values, labels = abs(breaks_values)) +
coord_flip() +
theme_economist_white(gray_bg = FALSE) +
scale_fill_manual(values = c("#1A476F", "#2D6D66")) +
labs(title = "Theme 1", x = "", y = "", fill = "") +
theme(legend.position = "none")

https://stackoverflow.com/questions/66716162
复制相似问题