Reputation: 2183
I'm plotting a series of data points, for which I need very specific symbols/shapes to represent each Country (it's not actually country but the real group will make no sense - I'm copying an old graph and want to keep the symbols consistent). There are nine different countries to plot. The easiest way I've found to do this so far is by coding the symbols I want in the actual dataframe like this:
Point y x Country
V 0.316 0.073 UK
P 0.284 0.053 USA
% 0.284 0.061 Germany
+ 0.314 0.072 France
| 0.268 0.075 Spain
h 0.313 0.0758 Canada
# 0.121 0.0623 Australia
i 0.234 0.0765 India
C 0.213 0.059 Norway
and then plotting like this:
ggplot(data, aes(x, y, label = Point, colour = Point)) + geom_text()
But this isn't particularly good when it comes to the legend:
How could I do this so that the Points become the symbols of the legend and then I can have the countries as the labels of the legend?
Upvotes: 3
Views: 774
Reputation: 578
Put shape=country
into aes()
and choose symbols using scale_shape_manual()
x=rnorm(10,1,2)
y=rnorm(10,1,2)
country=letters[1:10]
data=cbind.data.frame(x,y,country)
require(ggplot2)
ggplot(data,aes(x,y,shape=country))+
geom_point(size=6)+
scale_shape_manual(values=c("V","%","µ","@","#","V","%","µ","@","#"))
Upvotes: 4