[R] ggplot: Can plot graphs with points, can't plot graph with points and line

Sorkin, John j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Thu Jul 13 03:17:12 CEST 2023


I am trying to plot four points, and join the points with lines. I can plot the points, but I can't plot the points and the line.
I hope someone can help my with my ggplot code.

# load ggplot2
if(!require(ggplot2)){install.packages("ggplot2")}
library(ggplot2)

# Create data
Time       <- c("Age.25","Age.35","Age.45","Age.55")
Medians    <-c(128.25,148.75,158.5,168.75)
themedians <- matrix(data=cbind(Time,Medians),nrow=4,ncol=2)
dimnames(themedians) <- list(NULL,c("Time","Median"))
# Convert to dataframe the data format used by ggplot
themedians <- data.frame(themedians)
themedians

# This plot works
ggplot(themedians,aes(x=Time,y=Median))+
  geom_point()
# This plot does not work!
ggplot(themedians,aes(x=Time,y=Median))+
  geom_point()+
  geom_line()

Thank you,
John



More information about the R-help mailing list