Error while using geom_line in R

r
ggplot2

#1

I am currently working on one data set while working I am trying to plot using the ggplot2 package in R using geom_line as a layer above the plot.

ggplot(aes(x = gender, y = age),
+        data = subset(pf, !is.na(gender)))+geom_line(aes(color=gender),stat = 'summary',fun.y=median)

But I am getting only the empty plot by showing the comment on the console .
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?


#2

Hi @harry

When you are plotting the graph, you are using the following

  1. stat=‘summary’ : This one is a bit ambiguous
  2. fun.y=median : This is a valid case where you want to find the median value of the age of people of a particular gender

If you change the command to

ggplot(aes(x = gender, y = age),
+        data = subset(pf, !is.na(gender)))+geom_line(aes(color=gender),stat = 'sum',fun.y=median)

You will get the desired plot