I'm trying to create multiple line graphs using ggplot, geom_line and facet_wrap. The chart is created and displayed successfully, however the following message is also displayed along with the chart:
geom_path: Each group consists of only one observation. Do you need to adjust the group aesthetic?
I've already tried restarting my session, restarting R, searching for answers by Googling, searching here on Stack Overflow (including the following question: ggplot2 line chart gives "geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?") and can't find anything that helps.
Adding:
group=1
...doesn't eliminate the warning message.
The version of RStudio I'm using is: Version 1.1.463.
The code is in an RMarkdown file that I'm knitting to create an HTML document.
The libraries I'm using in this Rmarkdown file are:
library(tidyverse)
library(operators)
library(magrittr)
library(dplyr)
library(knitr)
library(sf)
library(usmap)
library(waffle)
The structure of the data set that I'm using in the chart is:
'data.frame': 75 obs. of 3 variables:
$ Year : int 1998 1993 1998 1999 2005 2007 2014 2018 1989 1991 ...
$ Age_Bracket : chr "1-12" "13-19" "13-19" "13-19" ...
$ Num_Shootings: num 1 1 1 1 1 2 1 2 1 1 ...
The code that generates the warning message is:
# Create a faceted line graph showing the number of mass shootings per year for each age bracket
faceted_line_graph_year_age <- ggplot(data=shootings_per_year_age, aes(x=Year, y = Num_Shootings, colour = Age_Bracket, group=1)) +
geom_line()+
geom_point()+
geom_smooth(method = "lm", colour = "#666666", linetype = 2, size = 0.5 )+
facet_wrap(~Age_Bracket)
# Display the faceted line graph
faceted_line_graph_year_age
The message I see is:
geom_path: Each group consists of only one observation. Do you need to
## adjust the group aesthetic?
I'm expecting the chart to be displayed without a warning message. What I'm getting is the chart displayed with a warning message.
geom_line
in the first group, because it cannot draw a line with only a single point there. This is also a warning/message (not sure which exactly here) but not an error, which would not have let you produce the graph at all. Warnings/messages are mostly to let you know you might be doing something wrong, not fatal – Calum YouGeomPath$draw_panel
, & I don't see anything there that could suppress the message. – Z.LinsuppressWarnings(...)
if you don't want to see warnings in a particular chunk of code. Or setoptions(warn=...)
to -1 - seehelp(options)
to see what the other values do. – Spacedmangeom_line
. If this geom can be removed without compromising the intent of the plot that is the simplest way to go. – DaveRGP