0

I made an empty plot to insert different figure inside. On the top I have a structure and below I would like to insert a graphical plot with point + curve linking the points. I also would like to set the color depending the value of y. I also would like to add the x and y axis on the graphical plot. I am stuck at the curve step color. Please see below the data and what I could do so far.

Any help will be appreciate

#data 

ya=c(9,78,90,45,76,36,79,32,87,90)
xa=sample(0:100, 10, replace=TRUE )

data_graph=data.frame(ya=ya, xa=xa) %>%
  mutate(color_point=ifelse(ya>0 & ya<=20, "green",
                     ifelse(ya>20 & ya<=40, "yellow",
                     ifelse(ya>40 & ya<=60, "orange",
                     ifelse(ya>60 & ya<=80, "red", 
                     ifelse(ya>80 & ya<=100, "brown", "NA")))))) %>%
  arrange(xa)

> data_graph
    ya xa color_point
1  32  9      yellow
2  78 31         red
3  36 31      yellow
4  90 42       brown
5   9 49       green
6  87 53       brown
7  45 61      orange
8  90 79       brown
9  76 80         red
10 79 92         red

# graph

plot(c(0,100), c(0,200),  type = "n", xaxt='n', yaxt='n')

points(x=data_graph$xa, y=data_graph$ya, pch=16, cex=1, col=data_graph$color_point)
lines(data_graph$xa, data_graph$ya)

rect(0, 148,100, 152) 
rect(20,140, 40, 160, col="blue")
rect(70,140, 80, 160, col="red")
rect(90,140, 95, 160, col="purple")

enter image description here

EDIT:

I found this function that could do the job but I don't know how to combine the different element. I am working on it, but if someone knows better this package, I take any ideas.

Thank you

library(plotrix)
my_colors = c("green", "yellow", "orange", "red", "brown")
clplot(data_graph$xa, data_graph$ya, main="", lwd=5, levels=c(20,40,60,80,100), col=my_colors, bty="n")

enter image description here

Patrick Parts
  • 203
  • 2
  • 9

0 Answers0