Hi Team,
I wrote the following code:
ggplot(try, aes(x = `_month`))+
geom_col(aes(y = Count), color="blue", fill="lightblue")+
geom_line(aes(y = Col_Rslt_TAT), color="#CC6666", linewidth = .8, group = 1) +
geom_line(aes(y = Rec_Rslt_TAT), color="#3399ff", linewidth = .8, group = 1) +
scale_color_manual(name = "Variable", values = c("Col_Rslt_TAT" = "#CC6666", "Rec_Rslt_TAT" = "#3399ff"), labels = c("Col_Rslt_TAT", "Rec_Rslt_TAT")) +
theme(legend.position="right")
In scale_color_manual part, I want to show a text box in right side to present the name of variable for each line. But it doesn't work and without error message.
Can you help me to fix the problem?
Thank you,
Kai
library(tidyverse)
try <- tibble(`_month`=1:12,
Col_Rslt_TAT=100-(1:12),
Rec_Rslt_TAT=60+(1:12)) |> mutate(Count=Col_Rslt_TAT + Rec_Rslt_TAT)
try_count <- select(try,`_month`,Count)
(try2 <- try |> select(-Count) |> pivot_longer(,cols=ends_with("TAT"),names_to = "Variable"))
ggplot(try_count, aes(x = `_month`))+
geom_col(aes(y = Count), color="blue", fill="lightblue")+
geom_line(data = try2,aes(y = value, color=Variable), linewidth = .8) +
scale_color_manual(name = "Variable",
values = c("Col_Rslt_TAT" = "#CC6666",
"Rec_Rslt_TAT" = "#3399ff")) +
theme(legend.position="right")
This way will create a new DF try2 and draw line chart using the try2 DF. I wondering if there is a way to add text box in the plot:
"Col_Rslt_TAT" using color #CC6666
"Rec_Rslt_TAT" using color #3399ff
and I want the text outside of the plot area
I add
+
labs(caption = "Col_Rslt_TAT, Rec_Rslt_TAT")
in the code. I can get the information on the bottom, but I don't know how to change the color
system
Closed
March 10, 2023, 10:11pm
6
This topic was automatically closed 42 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.