There are already many questions about this theme, but I could not find one that answered my specific problem.
I have a barplot
(see testplot1
The issue is that you are assigning fill = factor(colorname)
for the whole plot in your qplot
call.
So testplot2
will also try to map colorname
to the fill
aesthetic but there is no colorname
column in the pointdata
data.frame which is why you have this error message. If you rewrite it using ggplot
, it looks like this :
ggplot(bardata, aes(xname, yvalue, fill = factor(colorname))) +
geom_bar(stat = "identity")+
geom_point(data = pointdata,
mapping = aes(x = xname, y = ypos, shape = factor(ptyname)))
What you need to do is to apply the mapping only to the geom_bar
call, like this :
ggplot(bardata, aes(xname, yvalue)) +
geom_bar(stat = "identity", aes(fill = factor(colorname)))+
geom_point(data = pointdata,
mapping = aes(x = xname, y = ypos, shape = factor(ptyname)))