我正在尝试使用4个不同的组件绘制带有点和线的条形图。请告诉我如何给出包含所有四个组成部分的图例。 提前致谢。 我的代码是:
compend <- read_excel("compend.xlsx")
compend2 <- compend %>% filter(compend$yr == 2017) %>% group_by(`Name of the State/ UT`) %>% summarise_if(is.numeric, sum)
compend2 <- compend2[with(compend2, order(-`Total Liabilities`)), ]
positions <- compend2$`Name of the State/ UT`
plot1_name <- "Total Liabilities"
plot2_name <- "Deposits"
plot3_name <- "Loans & Advances"
plot4_name <- "Borrowings"
gp1 <- compend2 %>% ggplot(aes(group = 1)) +
geom_bar(mapping = aes(x = `Name of the State/ UT`, y = .data[[plot1_name]]),
stat = "identity", fill = "yellow", color = "Black") +
geom_point(mapping = aes(x = `Name of the State/ UT`, y = .data[[plot2_name]],
size = .data[[plot2_name]]), color = "Blue") +
geom_point(mapping = aes(x = `Name of the State/ UT`, y = .data[[plot3_name]],
size = .data[[plot3_name]]), color = "Red", shape = 15) +
geom_line(mapping = aes(x = `Name of the State/ UT`, y = .data[[plot4_name]]),
color = "#218906", size = 2) +
ylab(expression("Balance Sheet Size")) +
scale_x_discrete(limits = positions) +
scale_y_continuous(limits = c(0,12000000)) +
theme(legend.position = c(0.8, 0.8)) +
coord_flip()
gp1