0

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?

6
  • How to make a great R reproducible example? Commented Oct 8, 2015 at 16:49
  • It's hard to do reproducible example because I don't know why this happens (to recreate in the example), and the original data is big Commented Oct 8, 2015 at 16:52
  • Looks like rows in your data frame got re-ordered (mis-ordered). Commented Oct 8, 2015 at 17:13
  • @Gregor: I agree with you. But why this happens? I tried sort the data by: AGSN, id, piece and order, but didn't changed anything. Commented Oct 8, 2015 at 17:59
  • Do you have missing values in AGSN? If so you probably got a warning with your plot, but that could do it... Commented Oct 8, 2015 at 18:03

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.