0

I am trying to plot the vertical concentration profile of a pollutant. By convention, altitude is plotted on the vertical axis, and concentration is on the x (even though altitude is the independent variable). When plotting the concentrations for pollutants that do not fit a one-to-one function, R connects the points in a most annoying zig-zag pattern, instead of connecting them in order by altitude.

enter image description here

I tried changing the concentration values to factors, with levels based on altitude values:

concSummary$value <- factor(concSummary$value, levels = 
                            concSummary$value[order(concSummary$altitude)])

But this didn't seem to work. Does anyone know how to get around this problem?

jazzurro
  • 23,179
  • 35
  • 66
  • 76
Flora Su
  • 113
  • 7

1 Answers1

0

Update: Someone posted a useful solution here: controlling order of points in ggplot2 in R?

Using geom_path() instead of geom_point() tells R to connect points in the order in which they appear in a dataframe. This happened to work for me because the data were ordered by altitude.

Flora Su
  • 113
  • 7