Reputation: 460
I can't figure out how to add distance lines to the chart image below without it being a manual process. the code to add the points is simple. Any help would be greatly appreciated! The lines to need to be exactly like the image either.
##Example data
structure(list(Type = c("A", "A", "A", "B", "B", "C", "C", "C"
), Hz = c(50, 550, 1050, 800, 300, 50, 550, 1050), Vert = c(500,
500, 550, 600, 600, 700, 750, 700)), row.names = c(NA, 8L), class = "data.frame")
ggplot(ex, aes(Hz,Vert,color=Type))+theme_bw()+scale_y_reverse()+
geom_segment(aes(x = 50, y = 500, xend = 50, yend = 700),color='black',size=1)+
geom_segment(aes(x = 50, y = 600, xend = 300, yend = 600),color='red',size=1)+
geom_segment(aes(x = 50, y = 500, xend = 550, yend = 500),color='orange',size=1)+
geom_segment(aes(x = 50, y = 700, xend = 1050, yend = 700),color='green',size=1)+
geom_segment(aes(x = 550, y = 700, xend = 550, yend = 750),color='black',size=1)+
geom_segment(aes(x = 550, y = 500, xend = 550, yend = 600),color='blue',size=1)+
geom_segment(aes(x = 550, y = 500, xend = 550, yend = 600),color='purple',size=1)+
geom_segment(aes(x = 300, y = 600, xend = 550, yend = 600),color='pink',size=1)+
geom_segment(aes(x = 550, y = 600, xend = 800, yend = 600),color='orange',size=1)+
geom_point(size=5)
Upvotes: 1
Views: 125
Reputation: 2718
Would this qualify:
library(ggplot2)
df %>%
ggplot(aes(Hz, Vert, color = Type, group = 1)) +
geom_point(size = 10) +
scale_y_reverse() +
scale_color_manual(values = c("A" = "red", "B" = "#ffcc33", "C" = "#5b8551")) +
theme_minimal() +
geom_step(color = "black")
Upvotes: 3