Here is my code, the input file has a variable called region which is the state and the second variable is frequency, which is the number of responses by state. When I plot the data using this code I get triangles in the map as you can see. I am pretty sure the problem is in the sorting but after several tries I still can not get the triangles out. How do I sort these data to fix this problem? exiting result of this program
file_Path <-"c:/Map_data/map50.xlsx"
read.xlsx(xlsxFile ="c:/Map_data/map50.xlsx")
data<-read_excel("c:/Map_data/map50.xlsx")
state <-map_data("state")
comb<-left_join(data, state, by = "region")
finalmap<-ggplot(data=comb, aes(x=long, y=lat, fill=region, frequency=frequency)) +
geom_polygon(aes(fill=frequency), color ="green") +
scale_fill_gradient2(low="white",high="red",name=NULL) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45)+
ggtitle("Responses by State (2025)")+
theme(plot.title=element_text(size=15,hjust=0.5))
finalmap
finalmap<-finalmap[order(finalmap$group),]