I have the below data frame to demonstrate what I want.
library(ggplot2)
df1 <- data.frame(Methods = c('b', 'a', 'c', 'd', 'e'), lb = c(9, 7, 9, 4, 9), RMSE = c(0.26177952, 0.11294586, 0.02452239, 0.08290467, 0.41488542))
df1
Methods lb RMSE
1 b 9 0.26177952
2 a 7 0.11294586
3 c 9 0.02452239
4 d 4 0.08290467
5 e 9 0.41488542
An answer make the below solution:
df1 |>
ggplot(aes(x = Methods, y = RMSE, col = Methods)) + geom_point(size = 4) +
geom_segment(aes(x = Methods, xend = Methods, yend = RMSE, y = 0)) +
scale_color_manual(values = c("green", "yellowgreen", "yellow", "orange", "red")) +
theme_bw()
Here is the of the R code above:
The lollipop plot simply reveals one thing which is the height of RMSE
.
What I Want
In addition to the height of the
RMSE
, I want the colour to show the distribution of thelb
column.In the case of item 1 above, the
lb
variable (9
,7
,9
,4
,9
) and values oflb
should be attached to the chart legend.I want the minimum value of the
lb
variable to carrygreen
the next minimum to carryyellowgreen
, the middle value to carryyellow, the penultimate maximum to carry
orangeand the maximum value of the
lbvariable to carry
red`.If two methods have the same value of
lb
, give them the same colour then continue to the next value oflb
with the next colour.