0

OD Graph Example

Let me preface by saying that I am new to R and have limited coding experience. I have a data.frame with 4 different variables, three of which are factors (replicate, dilution, and hours). My final variable is the optical density which I need as a number value.

I'm looking to graph the differences of optical density across dilution based on hours (think bar graph with positive and negative values based on dilution). The real problem for me is that I don't know how to separate my data based on hours so I can find the difference in the density between them. I feel like this is a simple task, but everywhere I've looked has let me down the wrong path.

   Replicate pf_dilution hours    OD
1          1           0     0 0.050
2          2           0     0 0.045
3          3           0     0 0.061
4          1          10     0 0.155
5          2          10     0 0.138
6          3          10     0 0.135

Further down the list hours go to 24 and later 48.

  • 2
    It would help to provide more values in your example data (your hours are all 0). It would also help to provide some indication of the final output, or try to explain the procedure more clearly. It sounds like you want to plot OD versus dilution for different hours? But it isn't quite clear what the chart should look like. – neilfws Nov 16 '20 at 23:46
  • I want to plot the difference between the hours on the graph above for each dilution. So effectively there would be two bars (between day 0-1 and 1-2) for each dilution. I'm having trouble writing code to show that difference graphically. – horseradishbreeder Nov 17 '20 at 00:21
  • Welcome to Stack Overflow! Please check [this post on how to produce a reproducible example of your data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will allow other people to help you. – LuizZ Nov 17 '20 at 01:31

1 Answers1

0

Graphing the data set

df %>%
  group_by(hours) %>%
  ggplot(aes(x = pf_dilution, y = OD)) +
  geom_col(aes(fill = hours), position = position_dodge()) +
  labs(title = "Optical Density of C. elegans against P. fluorescens ",
       x = "PF Concentration [uL]",
       y = "OD") +
  scale_x_continuous(breaks = seq(0, 100, 10)) +
  scale_fill_discrete(name = "Hours")

enter image description here

Data

df <- read.table(text = "
   Replicate pf_dilution hours OD
   1 0 0 0.05 
   2 0 0 0.045 
   3 0 0 0.061 
   1 10 0 0.155 
   2 10 0 0.138 
   3 10 0 0.135 
   1 20 0 0.234 
   2 20 0 0.212 
   3 20 0 0.23 
   1 30 0 0.31 
   2 30 0 0.278 
   3 30 0 0.279 
   1 40 0 0.372 
   2 40 0 0.392 
   3 40 0 0.367 
   1 50 0 0.426 
   2 50 0 0.464 
   3 50 0 0.443 
   1 60 0 0.524 
   2 60 0 0.546 
   3 60 0 0.544 
   1 70 0 0.624 
   2 70 0 0.587 
   3 70 0 0.55 
   1 80 0 0.638 
   2 80 0 0.658 
   3 80 0 0.658 
   1 90 0 0.721 
   2 90 0 0.711 
   3 90 0 0.711 
   1 100 0 0.791 
   2 100 0 0.791 
   3 100 0 0.784 
   1 0 24 0.059 
   2 0 24 0.065 
   3 0 24 0.063 
   1 10 24 0.132 
   2 10 24 0.106 
   3 10 24 0.108 
   1 20 24 0.186 
   2 20 24 0.158 
   3 20 24 0.184 
   1 30 24 0.235 
   2 30 24 0.206 
   3 30 24 0.191 
   1 40 24 0.263 
   2 40 24 0.296 
   3 40 24 0.255 
   1 50 24 0.304 
   2 50 24 0.333 
   3 50 24 0.329 
   1 60 24 0.358 
   2 60 24 0.414 
   3 60 24 0.414 
   1 70 24 0.512 
   2 70 24 0.438 
   3 70 24 0.438 
   1 80 24 0.509 
   2 80 24 0.487 
   3 80 24 0.481 
   1 90 24 0.573 
   2 90 24 0.528 
   3 90 24 0.525 
   1 100 24 0.633 
   2 100 24 0.602 
   3 100 24 0.607 
   1 0 48 0.473 
   2 0 48 0.392 
   3 0 48 0.486 
   1 10 48 0.473 
   2 10 48 0.473 
   3 10 48 0.491 
   1 20 48 0.466 
   2 20 48 0.437 
   3 20 48 0.487 
   1 30 48 0.469 
   2 30 48 0.435 
   3 30 48 0.424 
   1 40 48 0.431 
   2 40 48 0.439 
   3 40 48 0.414 
   1 50 48 0.42 
   2 50 48 0.423 
   3 50 48 0.402 
   1 60 48 0.42 
   2 60 48 0.523 
   3 60 48 0.53 
   1 70 48 0.531 
   2 70 48 0.464 
   3 70 48 0.45 
   1 80 48 0.502 
   2 80 48 0.511 
   3 80 48 0.482 
   1 90 48 0.549
   2 90 48 0.516 
   3 90 48 0.488 
   1 100 48 0.627 
   2 100 48 0.562 
   3 100 48 0.583
   ",
   header = TRUE,
   colClasses = c("factor", "integer", "factor", "double")
)
tonybot
  • 643
  • 2
  • 10