I am trying to create a plot with multiple linear lines using ggplot2 in R, where each line represents a response of a separate individual to a change in the environment on the x-axis. I can make this plot no problem using the script provided below, however, I want the length of each line for each individual to represent the range of data each individual was sampled under (some lines will obviously be longer than others).
This link (http://www.intechopen.com/source/html/18476/media/image4.jpeg) will show you how I sort of want to final graph to look like, except I only need 1 frame (not 9), and the lines will vary in length. Also, the data on my x-axis is continuous, not discrete.
It seems that I may need to use geom_linerange
, but adjusting ymin and ymax doesn't seem to make sense, since I am actually trying to limit the range over the x-axis.
Any help is greatly appreciated!
This code will produce the plot from the data below.
p <- qplot(dBLevel,LowFreq, group=Male,data=test,geom="line")
Data subset ('Upper' and 'Lower' represent the range of the environmental variable (dBLevel) each 'Male' was sampled under. 'LowFreq' is the response variable to 'dBLevel'.)
test <- structure(list(Male = c(69L, 69L, 69L, 69L, 69L, 113L, 113L,
113L, 113L, 113L, 126L, 126L, 126L, 126L, 126L, 143L, 143L, 143L,
143L, 143L, 155L, 155L, 155L, 155L, 155L, 178L, 178L, 178L, 178L,
178L, 186L, 186L, 186L, 186L, 186L, 193L, 193L, 193L, 193L, 193L
), dBLevel = c(-20L, -10L, 0L, 10L, 20L, -20L, -10L, 0L, 10L,
20L, -20L, -10L, 0L, 10L, 20L, -20L, -10L, 0L, 10L, 20L, -20L,
-10L, 0L, 10L, 20L, -20L, -10L, 0L, 10L, 20L, -20L, -10L, 0L,
10L, 20L, -20L, -10L, 0L, 10L, 20L), LowFreq = c(3093.5, 3142.7,
3191.9, 3241.2, 3290.4, 3017.7, 3218.1, 3418.6, 3619, 3819.4,
2986.1, 3251.1, 3516.2, 3781.2, 4046.3, 2776.5, 2793.1, 2809.8,
2826.4, 2843.1, 3207.8, 3306.2, 3404.5, 3502.8, 3601.2, 2813.1,
2834.5, 2855.9, 2877.2, 2898.6, 4468.3, 4461.2, 4454.2, 4447.1,
4440.1, 2498.5, 2596.9, 2695.4, 2793.8, 2892.3), Upper = c(3.7,
3.7, 3.7, 3.7, 3.7, 12.23, 12.23, 12.23, 12.23, 12.23, -3.96,
-3.96, -3.96, -3.96, -3.96, -3.22, -3.22, -3.22, -3.22, -3.22,
-11.34, -11.34, -11.34, -11.34, -11.34, 15.34, 15.34, 15.34,
15.34, 15.34, -6.75, -6.75, -6.75, -6.75, -6.75, -0.67, -0.67,
-0.67, -0.67, -0.67), Lower = c(-2.71, -2.71, -2.71, -2.71, -2.71,
-1.31, -1.31, -1.31, -1.31, -1.31, -16.17, -16.17, -16.17, -16.17,
-16.17, -15.28, -15.28, -15.28, -15.28, -15.28, -15.79, -15.79,
-15.79, -15.79, -15.79, -3.79, -3.79, -3.79, -3.79, -3.79, -20.19,
-20.19, -20.19, -20.19, -20.19, -8.24, -8.24, -8.24, -8.24, -8.24
)), .Names = c("Male", "dBLevel", "LowFreq", "Upper", "Lower"
), row.names = c(NA, 40L), class = "data.frame")