Need help formatting for graph

data$variable.n <- read.table(data$variable header=TRUE, text=" 
Pipette  Volume  Before  After
100  10  1.833  1.844
100  30  1.844  1.864
100  45  1.864  1.878
100  55  1.878  1.883
100  80  1.883  1.914
100  99  1.914  1.929
1000  100  1.833  1.930
1000  250  1.930  2.063
1000  400  2.063  2.212
1000  600  2.212  2.407
1000  750  2.407  2.562
1000  999  2.562  2.816")
pipetteframe$Mass <- pipetteframe$After - pipetteframe$Before
biglm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="1000H"))
summary(biglm)
littlelm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="100C"))
summary(littlelm)

What are you trying to graph? What have you already tried?

I'm trying to graph the second and fourth columns on a line graph, but I need to be able to place the rows that start with 100 on one line while the rows with 1000 are on a different line. I've tried this:

pipetteframe <- read.table(header=TRUE, text="
Pipette  Volume  Before  After
100  10  1.833  1.844
100  30  1.844  1.864
100  45  1.864  1.878
100  55  1.878  1.883
100  80  1.883  1.914
100  99  1.914  1.929
1000  100  1.833  1.930
1000  250  1.930  2.063
1000  400  2.063  2.212
1000  600  2.212  2.407
1000  750  2.407  2.562
1000  999  2.562  2.816")
pipetteframe$Mass <- pipetteframe$After - pipetteframe$Before
biglm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="1000H"))
summary(biglm)
littlelm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="100C"))
summary(littlelm)

but, I've never really used Rstudio before so I'm not quite sure what I'm doing.

That last post was a copy of the original, but I meant to send this for what I've already tried. Thank you.

x <- pipette$volume
y <- pipette$mass
plot(x, y, main = "Mass vs Volume of Water", xlab = "Volume (microliters)", ylab = "Mass (grams)", pch = 19, frame = FALSE)
abline(lm(y ~ x, data = pipette), col = "blue")
Data <- data.frame(a = c(10,30,45,55,80,99), b = c(1.844,1.864,1.878,1.883,1.914,1.929))
names(Data) <- c("Volume", "Mass")
Data
Volume Mass
    10    1.844
    30    1.864
    45    1.878
    55    1.883
    80    1.914
    99    1.929
Data$Volume <- as.factor(Data$Volume) 
Data$Mass <- as.numeric(Data$Mass)
str(Data)
'data.frame':	4 obs. of  2 variables:
 $ Volume: Factor w/ 2 levels "1","2": 10 30 45 55 80 99
 $ Mass  : num  1.844 1.864 1.878 1.883 1.914 1.929
pipetteframe$Mass <- pipetteframe$After - pipetteframe$Before
biglm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="1000H"))
summary(biglm)
littlelm <- lm(Mass ~ Volume, data=pipetteframe, subset=(Pipette=="100C"))
summary(littlelm)

I would suggest using the ggplot2 package. In the example below, the x variable is Volume, the y-variable is Mass, and the group variable is Pipette which lets geom_line and geom_smooth know to put those on different lines.

pipetteframe <- read.table(header=TRUE, text="
Pipette  Volume  Before  After
100  10  1.833  1.844
100  30  1.844  1.864
100  45  1.864  1.878
100  55  1.878  1.883
100  80  1.883  1.914
100  99  1.914  1.929
1000  100  1.833  1.930
1000  250  1.930  2.063
1000  400  2.063  2.212
1000  600  2.212  2.407
1000  750  2.407  2.562
1000  999  2.562  2.816")

pipetteframe$Mass <- pipetteframe$After - pipetteframe$Before

library(ggplot2)

ggplot(pipetteframe, aes(x=Volume, y=Mass, group=Pipette)) +
  geom_line()


ggplot(pipetteframe, aes(x=Volume, y=Mass, group=Pipette)) +
  geom_point() +
  geom_smooth(method="lm", se=FALSE)
#> `geom_smooth()` using formula 'y ~ x'

Created on 2020-08-21 by the reprex package (v0.3.0)

That worked. Thank you so much.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.