• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
7 views

Problem :

Getting following issue  ggplot2 error

geom_path issue: each group consists of only one observation. Should i adjust the group aesthetic?

by (6.9k points)  
edited by

1 Answer

0 votes

Solution :

Start up R in a fresh session and please use bellow code:

library(ggplot2)

df <- structure(list(year = c(1, 2, 3, 4), pollution = structure(c(346.82, 
134.308821199349, 130.430379885892, 88.275457392443), .Dim = 4L, .Dimnames = list(
    c("1999", "2002", "2005", "2008")))), .Names = c("year", 
"pollution"), row.names = c(NA, -4L), class = "data.frame")

df[] <- lapply(df, as.numeric) # make all columns numeric

ggplot(df, aes(year, pollution)) +
           geom_point() +
           geom_line() +
           labs(x = "Year", 
                y = "Particulate matter emissions (tons)", 
                title = "Motor vehicle emissions in Baltimore")
This will solve your problem
by (20.3k points)  
...