Creating a plot by using data.frame

Hi. I created a data.frame which compares the average and standard deviations of baby’s birth weights among smoking mothers and non-smoking mothers. Here is what I have:

Situation <- c("Smoke","NonSmoke")
AverageWt <- c(meansmoke, meannonsmoke)
StdWt <- c(sdsmoke,sdnonsmoke)
d <- data.frame(Situation, AverageWt, StdWt, stringsAsFactors = FALSE)

And here is the result:

Situation AverageWt StdWt
1 Smoke 114.1095 18.09895
2 NonSmoke 123.0472 17.39869

Now what I'm trying to do is to use a plot to visualize the differences between them. Could anyone please help me? Thank you.

There are many ways to do this. Here is one using the StdWt values to define error bars.


DF <- data.frame(Situation = c("Smoke", "NonSmoke"),
                 AverageWt = c(114.1095, 123.0472),
                 StdWt = c(18.09895, 17.39869))
DF
#>   Situation AverageWt    StdWt
#> 1     Smoke  114.1095 18.09895
#> 2  NonSmoke  123.0472 17.39869
library(ggplot2)
ggplot(DF, aes(Situation, AverageWt)) + geom_point() +
  geom_errorbar(aes(ymin = AverageWt - StdWt, ymax = AverageWt + StdWt), width = 0.1)

Created on 2020-01-25 by the reprex package (v0.3.0)

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