Connect dots in qplot with adjacent y, not x

I make graphs of environmental measurements along vertical profiles, for example. down the siege core or as a function of depth in the ocean. By convention, these graphs are presented vertically, with an independent variable (depth) along the y axis. Therefore, the lines should connect the points of the adjacent value of y.

The "line" geometry in ggplot2 seems to only connect the points of the adjacent x value. Is there any way around this?

This example creates some realistic data and illustrates the problem:

#generate fake data sites<-factor(c(rep("site A", 10), rep("site B", 10))) depths<-rep(1:10, 2) values<-c(runif(10), runif(10)+2) #make a visually pleasing scatter plot qplot(values, depths, geom="point", col=sites) 

You can see on this plot that we are looking at measurements related to depth. But:

 #make a visually meaningless scatter plot qplot(values, depths, geom="line", col=sites) 

connects the points in a meaningless way. Is there a way to tie the dots vertically?

+4
source share
1 answer
 qplot(depths, values, geom="line", group=sites) + coord_flip() 

enter image description here

+5
source

Source: https://habr.com/ru/post/1379757/


All Articles