Rcoster
Rcoster

Reputation: 3210

Strange behavior on ggplot2

I'm trying to do a map to identify specific areas by coloring them. First, I made this plot to check if the data was ok (Setor is the sector's number):

ggplot(aes(x = long, y = lat, fill = Setor), data = mapa2010) + geom_polygon(colour = 'black') # data is ok

enter image description here

Them I tried to made the plot, filling by another variable (AGSN):

ggplot(aes(x = long, y = lat, fill = AGSN), data = mapa2010) + geom_polygon(colour = 'black')

enter image description here

The data is exactly the same, there is no code lines between this 2 commands. I've already tried to reorder the data, but still wrong.

Anyone know why this happens, and how to solve it?

Upvotes: 0

Views: 70

Answers (1)

Rcoster
Rcoster

Reputation: 3210

Adding the parameter group = group in aes() for second plot solve. Don't know why only the second map needs.

ggplot(aes(x = long, y = lat, fill = AGSN, group = group), data = mapa2010[order(AGSN, id, piece, order), ]) + geom_polygon(colour = 'black')

enter image description here

Upvotes: 1

Related Questions