折线图

通用代码

ggplot(data = frequent, aes(x = V1, y = V2, color = V3)) +
  geom_line() +
  theme_bw() +
  theme(
    panel.grid = element_blank(),
    panel.background = element_blank(),
    axis.line = element_line(size = 0.5, color = "black"),
    axis.text.x = element_text(size = "15"),
    axis.text.y = element_text(size = "15"),
    axis.title.y = element_text(size = "15"),
    axis.title.x = element_text(size = "15"),
  ) +
  scale_color_manual(values = c(
    "#00b894", "#d63031", "#1289A7", "#FFC312" #设置线条颜色
  )) +
  geom_vline(aes(xintercept = 51), linetype = "dashed", size = 0.2) + #增加垂直线
  scale_x_continuous(
    limits = c(1, 101), 
    breaks = seq(1, 101, 20),
     labels = c("-50", "-30", "-10", "10", "30", "50")) + #改变X轴刻度及刻度间跨度 
  annotate(
    geom = "text", x = 51, y = 0, label = "plot(A)", size = 4) + #增加注释文字
  xlab("Position") +
  ylab("Frequency")

改变线条颜色

  • scale_fill_manual() for box plot, bar plot, violin plot, etc

  • scale_color_manual() for lines and points

隐藏图例

p+guides(color=FALSE) //隐藏由color产生的图例
p+guides(color=guide_legend(title=NULL)) //隐藏color产生的图例的标题

参考

颜色设置 https://blog.csdn.net/chang349276/article/details/77476848

图例操作 https://blog.csdn.net/bone_ace/article/details/47284805

Last updated