问题,下面的图例不好看,怎么办:
dat6
5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 9L, 9L, 9L, 10L,
10L, 10L, 11L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L,
14L, 15L, 15L, 15L, 16L, 16L, 16L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L), .Label = c("Pilot", "2H2018", "201901", "201902", "201903",
"201904", "201905", "201906", "201907", "201908", "201909", "201910",
"201911", "201912", "202001", "202002"), class = "factor"), Grade = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("A",
"B", "C", "Total"), class = "factor"), Percent_with_Co = c(63,
27, 10, 56, 33, 12, 57, 30, 13, 61, 29, 11, 64, 27, 9, 65, 26,
9, 64, 26, 10, 64, 26, 10, 65, 25, 10, 65, 25, 10, 65, 25, 10,
69, 22, 9, 66, 23, 10, 65, 23, 12, 62, 27, 11, 64, 25, 10, 41,
43, 42, 45, 46, 42, 40, 41, 42, 40, 40, 40, 38, 37, 39, 40)), row.names = c(NA,
-64L), class = "data.frame")
ggplot(data = dat6, aes(x=Vintage, y = Percent_with_Co, group = Grade)) +
geom_line(aes(color=Grade), size=1.25) +
scale_color_manual(values=c("black", "gray40", "grey", "red")) +
labs(title = "Title") +
theme_bw() +
ylim(0,80) +
theme(legend.position = "bottom",
legend.direction = "horizontal",
legend.title = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.title = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
theme(axis.text.x = element_text(angle = 90),
axis.text.x.bottom = element_text(vjust = 0.5)) +
geom_text(aes(label = paste0(Percent_with_Co,"%"),
x = Vintage,
y = Percent_with_Co,
color=Grade),
vjust = -1,
hjust = .2,
size = 3)
解决方案:
ggplot(data = dat6, aes(x=Vintage, y = Percent_with_Co, group = Grade)) +
geom_line(aes(color=Grade), size=1.25) +
scale_color_manual(values=c("black", "gray40", "grey", "red")) +
labs(title = "Title") +
theme_bw() +
ylim(0,80) +
theme(legend.position = "bottom",
legend.direction = "horizontal",
legend.title = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.title = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank()) +
theme(axis.text.x = element_text(angle = 90),
axis.text.x.bottom = element_text(vjust = 0.5)) +
geom_text(aes(label = paste0(Percent_with_Co,"%"),
x = Vintage,
y = Percent_with_Co,
color=Grade),
vjust = -1.5,
hjust = .2,
size = 3,
fontface = "bold",
show.legend = FALSE)