更改绘图内的颜色

时间:2021-02-09 22:54:06

标签: r ggplot2

在这个情节

library(ggplot2)

df <- data.frame(year = c(2011,2012,2013,2014,2015,2016,2017,2018), 
                 value = c(337,423,551,661,846,1387,2222,3580))

ggplot(df, aes(year, value)) +
  geom_point() +
  geom_line() +
  geom_text(aes(label = value, y = (value - 50)*0.9))

如何将数值的颜色变成红色?

1 个答案:

答案 0 :(得分:0)

喜欢吗?

library(ggplot2)

df <- data.frame(year = c(2011,2012,2013,2014,2015,2016,2017,2018), 
                 value = c(337,423,551,661,846,1387,2222,3580))

ggplot(df, aes(year, value)) +
  geom_point() +
  geom_line() +
  geom_text(aes(label = value, y = (value - 50)*0.9), color = "red")

example.png

或者像这样?

library(ggplot2)

df <- data.frame(year = c(2011,2012,2013,2014,2015,2016,2017,2018), 
                 value = c(337,423,551,661,846,1387,2222,3580))

ggplot(df, aes(year, value)) +
  geom_point() +
  geom_line() +
  geom_text(aes(label = value, y = (value - 50)*0.9), color = "red") +
  theme(axis.text.y = element_text(colour = "red"))

example_2.png