I'm having trouble substituting color() for facet_grid() when I want to 'split' my data by a variable. Instead of generating individual plots with regression lines, I'm looking to generate a single plot with all regression lines.
Here's my code:
ggplot(data, aes(x = Rooms, y = Price)) +
geom_point(size = 1, alpha = 1/100) +
geom_smooth(method = "lm", color = Type) # Single plot with all regression lines
ggplot(data, aes(x = Rooms, y = Price)) +
geom_point(size = 1, alpha = 1/100) +
geom_smooth(method = "lm") + facet_grid(. ~ Type) # Individual plots with regression lines
(The first plot doesn't work) Here's the output: "Error in grDevices::col2rgb(colour, TRUE) : invalid color name 'Type' In addition: Warning messages: 1: Removed 12750 rows containing non-finite values (stat_smooth). 2: Removed 12750 rows containing missing values (geom_point)."
Here's a link to the data: Dataset
colour
argument insideaes
and instead passed it togeom_smooth
directly. – Calum You