有关geom_地图的错误:“1”;单位错误(x,默认单位):&x27;x';和';单位';必须具有长度>;0“; 库(dplyr) 图书馆(绘本) 图书馆(韦斯安德森) 图书馆(动画) 图书馆(主题) 图书馆(比例尺) 状态映射

有关geom_地图的错误:“1”;单位错误(x,默认单位):&x27;x';和';单位';必须具有长度>;0“; 库(dplyr) 图书馆(绘本) 图书馆(韦斯安德森) 图书馆(动画) 图书馆(主题) 图书馆(比例尺) 状态映射,r,animation,ggplot2,R,Animation,Ggplot2,在两行上更改大小写: library(dplyr) library(plotly) library(wesanderson) library(animation) library(ggthemes) library(scales) states_map <-map_data("state") StateCodes <- c("AL","AK","CA","AL","AK","CA") year <- c(2010,2010,2010,2011,2011,2011) n <

在两行上更改大小写:

library(dplyr)
library(plotly)
library(wesanderson)
library(animation)
library(ggthemes)
library(scales)
states_map <-map_data("state")

StateCodes <- c("AL","AK","CA","AL","AK","CA")
year <- c(2010,2010,2010,2011,2011,2011)
n <- c(1.1,1.2,1.3,2.1,2.2,2.3)
data <- data.frame(StateCodes,year,n)

saveGIF({
  for (i in 2010:2011) {

    m<-ggplot(subset(data,year==i), aes(map_id = StateCodes)) +
      geom_map(aes(fill = (n)), map = states_map, color ="black") +
      expand_limits(x = states_map$long, y = states_map$lat) +
      theme_few()+
      theme(legend.position = "bottom",
            axis.ticks = element_blank(), 
            axis.title = element_blank(), 
            axis.text =  element_blank()) +
      scale_fill_gradient(low="white", high="blue") +
      guides(fill = guide_colorbar(barwidth = 10, barheight = .5)) + 
      ggtitle(paste("Value in Year",i))
    print(m)


  } 

}, interval = 1, movie.name = "value_usa.gif", ani.width = 800, ani.height = 600 )

Statecodes在两行上更改大小写:

library(dplyr)
library(plotly)
library(wesanderson)
library(animation)
library(ggthemes)
library(scales)
states_map <-map_data("state")

StateCodes <- c("AL","AK","CA","AL","AK","CA")
year <- c(2010,2010,2010,2011,2011,2011)
n <- c(1.1,1.2,1.3,2.1,2.2,2.3)
data <- data.frame(StateCodes,year,n)

saveGIF({
  for (i in 2010:2011) {

    m<-ggplot(subset(data,year==i), aes(map_id = StateCodes)) +
      geom_map(aes(fill = (n)), map = states_map, color ="black") +
      expand_limits(x = states_map$long, y = states_map$lat) +
      theme_few()+
      theme(legend.position = "bottom",
            axis.ticks = element_blank(), 
            axis.title = element_blank(), 
            axis.text =  element_blank()) +
      scale_fill_gradient(low="white", high="blue") +
      guides(fill = guide_colorbar(barwidth = 10, barheight = .5)) + 
      ggtitle(paste("Value in Year",i))
    print(m)


  } 

}, interval = 1, movie.name = "value_usa.gif", ani.width = 800, ani.height = 600 )

Statecodes
Statecodes
包含
states\u map
中的
区域
的缩写,这些区域的全称。我建议保持一致。我在运行线路时遇到了一个错误,states_map@Haboryme是的,你是对的。直到你指出我的愚蠢错误,我才意识到。谢谢大家!
Statecodes
包含
州地图
中的
地区
的缩写,这些地区的全称。我建议保持一致。我在运行线路时遇到了一个错误,states_map@Haboryme是的,你是对的。直到你指出我的愚蠢错误,我才意识到。非常感谢。