I am trying to connect the geom_points in my ggplot with geom_path. The lines should be in the same color as the geom_point fill color. However, geom_path does not know fill and color is used for a different grouping.
I am also highlighting certain geom_points with black outline using
scale_color_manual(values = c("NA", "black"), labels = c("No Buy Box", "Buy Box"))
What can I do? In fact, I want to plot the dots in different color (fill) by seller_id, highlight certain of these dots with colour = black if bbox = 1 and in addition connect the dots in their color using geom_path. I assume there are some more general issues in how I layered up the graphs in terms of the sub-sampling. geom_path does not know fill, this would have been the easiest solution. A data snippet is at the end to this post.
Thank you!!
ggplot(data = subset(algo_pricing,bbox_product == 9200000096286280), aes(x = bbox_time2)) +
geom_point(mapping = aes(y = price_total, colour = as.factor(bbox), fill = seller_id), shape = 21) +
geom_line(data = subset(algo_pricing, bbox ==1 & bbox_product == 9200000096286280),
mapping = aes(y = bbox_price, linetype = as.factor(bbox)),colour = "black") +
geom_path(mapping = aes(y = price_total, colour = seller_id), linetype = "dotted") +
scale_linetype_manual(values = "dotted", labels = "Buy Box Price") +
scale_color_manual(values = c("NA", "black"), labels = c("No Buy Box", "Buy Box"))
example <- wrapr::build_frame(
"bbox_time2" , "bbox_price", "price_total", "seller_id" , "bbox", "min_price", "bbox_product" |
as.Date("2019-01-07"), 151 , 169.9 , "linkerlisse" , 0L , 129.5 , 4.641e-308 |
as.Date("2019-01-18"), 125 , 169.9 , "linkerlisse" , 0L , 112 , 4.641e-308 |
as.Date("2019-01-20"), 125 , 169.9 , "goedslapennl" , 0L , 118.5 , 4.641e-308 |
as.Date("2019-01-14"), 120 , 169.9 , "decoware" , 0L , 114.3 , 4.641e-308 |
as.Date("2019-01-18"), 125 , 169.9 , "goedslapennl" , 0L , 112 , 4.641e-308 |
as.Date("2019-01-19"), 125 , 125 , "bol.com" , 1L , 125 , 4.641e-308 |
as.Date("2019-01-20"), 125 , 169.9 , "decoware" , 0L , 121 , 4.641e-308 |
as.Date("2019-01-19"), 125 , 169.9 , "decoware" , 0L , 124.2 , 4.641e-308 |
as.Date("2019-01-10"), 135 , 120.3 , "hetbestebeddengoed.nl", 0L , 120.3 , 4.641e-308 |
as.Date("2019-01-11"), 135 , 135 , "bol.com" , 1L , 115.5 , 4.641e-308 |
as.Date("2018-12-31"), 151 , 151 , "bol.com" , 1L , 143.8 , 4.641e-308 |
as.Date("2019-01-17"), 125 , 169.9 , "goedslapennl" , 0L , 116.2 , 4.641e-308 |
as.Date("2019-01-20"), 125 , 169.9 , "goedslapennl" , 0L , 119.8 , 4.641e-308 |
as.Date("2019-01-17"), 125 , 169.9 , "goedslapennl" , 0L , 115.5 , 4.641e-308 |
as.Date("2019-01-22"), 112.3 , 112.3 , "hetbestebeddengoed.nl", 1L , 112.3 , 4.641e-308 |
as.Date("2019-01-01"), 151 , 169.9 , "linkerlisse" , 0L , 142.1 , 4.641e-308 |
as.Date("2019-01-21"), 125 , 127.5 , "sleepworld" , 0L , 117.8 , 4.641e-308 |
as.Date("2018-12-31"), 151 , 151 , "bol.com" , 1L , 142.8 , 4.641e-308 |
as.Date("2019-01-18"), 125 , 169.9 , "smulderstextiel.nl" , 0L , 125 , 4.641e-308 |
as.Date("2019-01-01"), 151 , 169.9 , "linkerlisse" , 0L , 141.2 , 4.641e-308 )

dput(your.data.frame)or at least a portion of it so that we can have a reproducible example? - chemdork123sample()to grab a few rows from your original dataframe: (e.g.algo_pricing[sample(1:nrow(algo_pricing), 20),]would work to grab 20 rows randomly), but you would want to make sure your example works with your dataset you post. Additionally, what are you getting as a result of your code, and where does it seem to go wrong? Are you generating a plot that doesn't look right or are you getting an error message? - chemdork123scale_color_manualandscale_linetype_manualcalls. That will generate a plot, but probably it's not what you want to see.ggplotwill combine scales when you specify the same aesthetic: so for example, you specify to apply the linetype ofgeom_lineand outside color ofgeom_pointto the same factor (as.factor(bbox)). A legend is created that indicates bbox as being either dotted with one color or solid as another color (combining the two). Remove thosescale_...calls, post your plot, then clarify your question - probably concerning the legend and labeling. - chemdork123