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

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Sat Jul 1 20:43:14 CEST 2023

```Can your post a few lines of your data frame (e.g. via
dput(head(...))) to make it clearer. I found this statement confusing:
"... 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."

This might or might not be the source of your problems, but I think
showing us (enough of) your data would help clarify things. I don't
use ggplot, but someone who does might have a better chance of
pinpointing the problem if you provide such data.

Cheers,
Bert

On Sat, Jul 1, 2023 at 11:21 AM Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
>
> 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
> 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
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help