Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

r - Add a multi-line text box at the end of individual geom_line plots

I create a plot in ggplot with four different individual geom_line plots (that is my data frame is in a wide format). I hope to add a text box in the end of the plot that gives the label name and tells how much the plot has changed in percentage terms from the first observation.

I know how to add regular text (even a small text box with the label name) at the end of the line, however I need two features which I have not found answered elsewhere (that is it is not answered Text for example, namely that the data is set up in a wide format, and that the text box should include something like 8-12 words not related to the label/column name

Below is some basic code which re-creates a dataset which I would use in the code

df <- data.frame("Year" = 2011:2020, a = seq(1,10,1), b = seq(2,13, length.out = 10))


p <- ggplot(df, mapping = aes(Year,a), linetype = "dotted") + 
  geom_line(colour = "blue", linetype = "dotted") +
  geom_line(df, mapping = aes(Year,b), colour = "black", linetype = "dotted") +
  labs(title="Predicted y", 
       subtitle="Subtitle", 
       y="Y name", 
       color=NULL) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "black"))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...