0
我想找到一種方法來取代11個時間段的連續標度到離散標度,我的意思是我有一個標度,其中分類是按百分比完成的,但現在我想用相應的11個時間段替換它在線路12(年)年如何用R代替地圖中的連續比例到離散比例尺?
請,如果有人能幫助我,我真的很感激它,在接下來的環節是數據庫,將R代碼(下同)https://www.dropbox.com/sh/rctlpzcv5nx0aun/AAAmRpSfSLiDeEu6Q0svr-tga
dat = read.csv("alexis.csv")
dat = melt(dat, id=c("Port", "latitude", "longitude"))
library(ggplot2)
library(cshapes)
library(reshape)
world = cshp(date=as.Date("2008-1-1"))
world.points = fortify(world)
names = unique(dat$variable)
year = c("1843", "1840-1845", "1869", "1866-1870", "1894", "1900 Dec.",
"1912", "1922", "1932", "1940", "1950")
dat$value = dat$value*100
dat$Pdiff = "<20%"
dat$Pdiff[dat$value<50 & dat$value>=20] = "<50%"
dat$Pdiff[dat$value<100 & dat$value>=50] = "<100%"
dat$Pdiff[dat$value<150 & dat$value>=100] = "<150%"
dat$Pdiff[dat$value<200 & dat$value>=150] = "<200%"
dat$Pdiff[dat$value<250 & dat$value>=200] = "<250%"
dat$Pdiff[dat$value<300 & dat$value>=250] = "<300%"
dat$Pdiff[dat$value>=300] = "<=300%"
dat$Pdiff = factor(dat$Pdiff)
reorder(X = dat$Pdiff, dat$Pdiff, new.order=c("<20%","<50%","<100%","<150%",
"<200%","<250%","<300%", "<=300%"))
years = c("1843", "1840-1845", "1869", "1866-1870", "1894", "Dec 1900",
"1912", "1922", "1932", "1940", "1950")
for(i in 1:length(names)){
temp = na.omit(dat[dat$variable==names[i],])
p1 = ggplot(world.points, aes(long, lat, group=group)) +
geom_polygon(fill="white") +
geom_point(data=temp, aes(x=longitude, y=latitude, group=value, col=value)) +
coord_equal() +
scale_x_continuous(labels=NULL) +
scale_y_continuous(labels=NULL) +
labs(x = NULL, y = NULL, fill = "% Irish") +
scale_colour_gradientn("Price Change %", colours=c("yellow", "red")) +
theme(axis.ticks = element_blank(), axis.text.y = element_blank(),
legend.position="bottom") +
ggtitle(years[i])
name = paste(paste("prch", i, sep=""), ".pdf", sep="")
ggsave(name, p1, width=8, height=4)
}