Thanks in advance for any assistance!
I am using ggplot and geom_point to plot various data points. I am classifying points according to two thresholds and would like to add vertical lines to indicate where these thresholds are with respect to the points. However, the lines are not in the correct place. After some troubleshooting, I realized they are mapping according to the x-axis tick number instead of the actual data points.
I have created a simplified version of my data and code. All points lie between 0 and 1 and the vertical lines representing the thresholds should lie at 0.4 and 0.75. Note that in the result (see image), they are both below 0.075 which is the value corresponding to the first tick on the x-axis.
Reproducible code:
# Create simple data frame
d <- data.frame( Name = c("name1", "name2", "name3", "name4", "name5","name6","name7", "name8", "name9"),
ICC = c("0.569", "0.981", "0.548", "0.599", "0.352", "0.075", "0.836", "0.637", "0.423"))
# Set up plot
p <- ggplot() +
geom_point(data = d, mapping = aes(x = ICC, y = Name)) +
geom_vline(data = d, mapping = aes(x = ICC), xintercept = 0.4, linetype = "dotted", color = "red", size = 1.5) +
geom_vline( data = d, mapping = aes(x = ICC), xintercept = 0.75, linetype = "dotted", color = "blue", size = 1.5)
The result:
Plot_showing_incorrect_line_placement
I read the documentation. I tried the alternative function, geom_segment. I tried every mapping/data specifying iteration I could think of. I’m stuck.
booVelvet is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.