Вы можете использовать следующий код
library(tidyverse)
test.data<-data.frame(TYPE=c("A","B","C","D"), D1=c(20,10,1,1.1),
D2=c(40,20,3,2), D3=c(9,30,8,3), D4=c(12,20,3,6), D5=c(30,10,6,3) )
df1 <- test.data %>%
pivot_longer(cols = -TYPE) %>%
subset(TYPE %in% c("A","B"))
df2 <- test.data %>%
pivot_longer(cols = -TYPE) %>%
subset(TYPE %in% c("C","D"))
ggplot() +
geom_col(data = df1, aes(x = name, y = value, fill = TYPE), position = position_dodge()) +
scale_fill_manual("Type", values = c("A" = "#56B4E9", "B" = "#E69F00"))+
geom_point(data = df2, aes(x = name, y = value*5, group = TYPE, col = TYPE)) +
geom_line(data = df2, aes(x = name, y = value*5, group = TYPE, col = TYPE)) +
scale_color_manual("Type", values = c("C" = "darkgrey", "D" = "black"))+
scale_y_continuous(name = "First Axis",
sec.axis = sec_axis(trans = ~.*1/5, name="Second Axis"))+
theme_bw()
введите описание изображения здесь