rWBclimate icon indicating copy to clipboard operation
rWBclimate copied to clipboard

error making historical world temperature map in rWBclimate

Open jackienyr93 opened this issue 9 years ago • 8 comments

trying to make a world temperature map from 1901 but run into error at the end

world <- c(NoAm_country,SoAm_country,Eur_country,Asia_country,Africa_country,Oceana_country) world_map_df <- create_map_df(world) world_dat4 <- get_historical_temp(world, "year") world_dat4_small<-subset(world_dat4, year >=1901 & year <= 1901, select=c(1:length(world_dat4))) world_dat4<- world_dat4[order(world_dat4$locator),] world_map_df <- world_map_df[order(world_map_df$ID),] world_map <- climate_map(world_map_df,world_dat4_small,return_map = TRUE)

Error in climate_map(world_map_df, world_dat4_small, return_map = TRUE) : You can't have more than one piece fo data for each region to map

this would be the rest of the code world_map + scale_fill_continuous("Temperature \n at 1901",low="yellow",high = "red") + theme_bw()

any help would be greatly appreciated. or if you have another way to make a world map with historical temperatures…preferably before cars/smoke/etc affected world temps. thx!

jackienyr93 avatar May 13 '15 02:05 jackienyr93

Hi @jackienyr93 I'm away today but I'll have a look this evening.

emhart avatar May 13 '15 16:05 emhart

awesome! thanks so much @emhart

jackienyr93 avatar May 14 '15 00:05 jackienyr93

@jackienyr93 Here's a fix for you. The main problem is that the countries in the data and in the map data frame don't match. In the code below I find the missing country and exclude it from the mapping data frame. In the future I'll fix this so it's transparent and still plots. The country causing our problems is "UMI" or "US Minor Islands". When I check where they have data from, there's no UMI data until 2010. Here's the code I used. Also, you don't need to re-order the data frame like you're doing, just run a basic subset will get the job done. Let me know if this fix works for you.

library(rWBclimate)
options(kmlpath="~/kmltmp")
world <- c(NoAm_country,SoAm_country,Eur_country,Asia_country,Africa_country,Oceana_country)
world_map_df <- create_map_df(world)
world_dat4 <- get_historical_temp(world, "year")
### Get the year of interest
world_dat_sm <- subset(world_dat4,year == 1901)

### See what country is missing...

unique(world_map_df$ID)[!unique(world_map_df$ID)%in%world_dat_sm$locator]=

### We see it's UMI causing the problem.

world_map_df <- subset(world_map_df,ID!="UMI")
world_map <- climate_map(world_map_df,world_dat_sm,return_map = TRUE)


world_map + scale_fill_continuous("Temperature \n at 1901",low="yellow",high = "red") + theme_bw()


climatefix

emhart avatar May 14 '15 05:05 emhart

@emhart thank you so much!!!! this worked perfectly!!!

jackienyr93 avatar May 15 '15 02:05 jackienyr93

I am having the same issue. I tried to use the example you posted on rOpenSci, but I am getting the same error as @jackienyr93. I used the code on here to figure out which missing data, but I'm getting a character(0) return. Could you please help me with my error?

library("rWBclimate") library("spocc") library("plyr") library("sp") dir.create("~/kmltmp") options(kmlpath="~/kmltmp") options(stringsAsFactors = FALSE) require(rWBclimate) usmex <- c(273:284, 328:365) usmex.basin <- create_map_df(usmex) temp.dat <- get_model_temp(usmex, type= "mavg", 2080, 2100) #mavg=monthly averages #2080 is start year #2100 is end year

temp.dat <- subset(temp.dat, temp.dat$year ==2080) #for year 2080 temp.dat <- subset(temp.dat, temp.dat$gcm=="ukmo_hadcm3") #general circulation model name ukmo_hadcm3 temp.dat <- subset(temp.dat, temp.dat$scenario!="b1") #b1 scenario with a more ecologically friendly world usmex.map.df <- climate_map(usmex.basin, temp.dat, return_map =F)
#return_map=F bc i need a dataframe where data items are matched to their
polygon that I can plot later on. Error in climate_map(usmex.basin, temp.dat, return_map = F) : You can't have more than one piece of data for each region to map

rockahominy avatar Mar 16 '18 01:03 rockahominy

any thoughts @emhart ?

sckott avatar Mar 21 '18 16:03 sckott

Hmmm, @chinchuharris does the fix in the issue not work anymore?

emhart avatar Mar 28 '18 15:03 emhart

@emhart That solution still works. I wasn't paying attention to the global environment in RStudio. I didn't have any data remaining after I ran all the subsets.

rockahominy avatar Apr 06 '18 01:04 rockahominy