[R] How to plot both lines and points by group on ggplot2

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Sat Jul 1 20:20:53 CEST 2023


Hello,
I have a dataframe with measurements stratified by the concentration
of a certain substance. I would like to plot the points of the
measures and connect the points within each series of concentrations.
When I launch ggplot2 I get the error
```
geom_path: Each group consists of only one observation. Do you need to
adjust the
group aesthetic?
```
and no lines are drawn.
Where am I going wrong?
Thank you
Luigi

```
df = data.frame(Conc = c(rep(1, 3), rep(2, 3), rep(5, 3)),
                Time = rep(1:3, 3),
                Value = c(0.91, 0.67, 0.71, 0.91, 0.65, 0.74, 0.95, 0.67, 0.67))
df$Time <- as.factor(df$Time)
levels(df$Time) = c(1, 4, 24)
df$Conc <- as.factor(df$Conc)
levels(df$Conc) = c(1, 2, 5)
library(ggplot2)
ggplot(df, aes(x=Time, y=Value, colour=Conc)) +
  geom_point(size=6) +
  geom_line(aes(x=Time, y=Value, colour=Conc)) +
  scale_colour_manual(values = c("darkslategray3", "darkslategray4",
                                 "deepskyblue4")) +
  ggtitle("Working example") +
  xlab(expression(bold("Time (h)"))) +
  ylab(expression(bold("Concentration (mM)")))
```
-- 
Best regards,
Luigi



More information about the R-help mailing list