I have a requirement where I want to combine two different scatter plot in the same plot area. One scatter plot is with metric 1 and another scatter plot with metric 2. Is it feasible in R ? I have added the dataset as well as code. But not sure how to merge these two within the same plot.
df1 <- data.frame(Product = c("A","B","C"),
ProductMetric = c("85","90","92"),
CategoryMetric = c("83"),
Category = c("AAA"))
df1
ggplot(data=df1, mapping= aes(x=Category,y= ProductMetric))+ geom_point(size=5)+
ggplot(data=df1, mapping= aes(x=Category,y= CategoryMetric))+ geom_point(size=5)
So basically after the combined result, there should be 4 circles in the same chart, Basically I want to show Product Avg and Category Avg with the circle in the same chart so that end user can compare the product avg with the category avg by just seeing the chart.
Regards, Akash
We can add a new
geom_point
layer and specifydata
to bedf1
andy
to beCategoryMetric
.You only need to convert your data from
wide
tolong
format usinggather
from thetidyr
package. Read more hereEdit: to keep
Category Ave
color inred
while changing the color and legend for eachProduct
dynamically depending on the number of products.Created on 2018-03-31 by the reprex package (v0.2.0).