0

I'm analysing a dataset where the temperature of 2 fingers on both hands has been measured for half an hour. I would like to make a line plot, with means and errorbars based on whether the hand received active treatment or not and which finger. Which means that the curves must be distiunguished by two variables and with x being time and y being temperature.

I have tried making it from the full dataset, however, did not come up with anything meaningfull. Then I have tried, where I seperate the dataset into two based on active or placebo treatment and then combine them again in the plot, but some of the lines does not cumpute with the aesthestics I have set.

I have tried the following webpage, however, with no luck: http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/

Any ideas? Thank you!

plot10 <- ggplot(data3, aes(x=time, y=temp, colour=finger, group=finger))+
  geom_errorbar(aes(ymin=temp-ci, ymax=temp+ci),colour="black", width=1, position=pd)+
  geom_line(position=pd, size=1)+
  geom_point(position=pd, size=3, shape=21, fill="white")+
  geom_line(data=data4, aes(x=time, y=temp, colour=finger, group=finger))+
  geom_errorbar(aes(ymin=temp-ci, ymax=temp+ci),colour="black", width=1, position=pd)+
  geom_line(position=pd, size=1)+
  geom_point(position=pd, size=3, shape=21, fill="white")+
  theme_bw()

Plot from above code:

Plot from above code

harre
  • 7,081
  • 2
  • 16
  • 28
  • 3
    Welcome to SO! It would be easier to help you if you provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Jul 20 '22 at 11:21
  • 1
    But from your plot it looks fine too me. You get lines, points and error bars for data3 and additional two lines (the botoom ones) for data4. One issue with your code is that you add the geom_line, geom_point and geom_errorbar for data3 a second time. – stefan Jul 20 '22 at 11:24
  • Hi Stefan. Many thanks for your response. I would like to make the lines for data4 look like the lines for data3. With the same line, point and errorbars. Mayby you have an idea how to do that? – NewbTown Jul 20 '22 at 12:34
  • 1
    Already guessed that. (: Add `data=data4` to the duplicated (the second) geom_point and geom_errorbar too (as you did for the second geom_line). Still the third geom_line is unnecessary. – stefan Jul 20 '22 at 12:37
  • I knew it probably was easier than I thought - I just really could'nt figure it out! Thank you Stefan - you're a hero :) – NewbTown Jul 21 '22 at 06:23

0 Answers0