ggplot2不要图例_如何控制ggplot2的legend图例

问题,下面的图例不好看,怎么办:

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值