code4cos
code4cos copied to clipboard
ggplot2那里有个问题
scale_area出错,帮助文档、、、、
scale_area {ggplot2} R Documentation
Scale area instead of radius (for size).
Description
scale_area is deprecated and will be removed in a future version of ggplot2. Use scale_size_area instead. Note that the default behavir of scale_size_area is slightly different: by default, it makes the area proportional to the numeric value.
改成scale_size_area 后不需要参数。
前面数据读取处理插值那里我是这样写的。
#data
data <- readLines("data/1800-2009年国家收入人口寿命数据.txt")
library(RJSONIO)
data <- fromJSON(data)
library(plyr)
data <- ldply(data,function(x){
name <- x$name
region <- x$region
incom_temp <- ldply(x$income,function(x)x)
population_temp <- ldply(x$population,function(x)x)
lifeExpectancy_temp <- ldply(x$lifeExpectancy,function(x)x)
year <- union(union(incom_temp$V1,population_temp$V1),lifeExpectancy_temp$V1)
temp <- merge(as.data.frame(year),incom_temp,by.x="year",by.y="V1",all=T)
temp <- merge(temp,population_temp,by.x="year",by.y="V1",all=T)
temp <- merge(temp,lifeExpectancy_temp,by.x="year",by.y="V1",all=T)
colnames(temp) <- c("year","incom","population","lifeExpectancy")
temp$name <- name
temp$region <- region
return(temp)
})
head(data)
country_name <- attributes(table(data$name))$dimnames[[1]]
year <- seq(min(data$year),max(data$year))
data_all <- data.frame()
sp <- function(x){
if(is.character(x)){
return(rep(x[!is.na(x)][1],length(x)))
}
nna <- which(!is.na(x))
na <- which(is.na(x))
for(i in na){
a <- nna[which(nna<i)]
a <- a[length(a)]
b <- nna[which(nna>i)]
if(length(b)>0){
b <- b[1]
}
if(length(a)==0){
x[i] <- x[b]
}else{if(length(b)==0){
x[i] <- x[a]
}else{x[i] <- mean(x[a],x[b])}}
}
x
}
for(i in country_name){
temp <- subset(data,name==i)
temp <- merge(as.data.frame(year),temp,by = "year",all = T)
temp$incom <- sp(temp$incom)
temp$population <- sp(temp$population)
temp$lifeExpectancy <- sp(temp$lifeExpectancy)
temp$name <- sp(temp$name)
temp$region <- sp(temp$region)
data_all <- rbind(data_all,temp)
}
我还是新手,后面的画图直接拷贝的、、、
好像因为ggplot2版本更迭我已经查不到range这个参数是干啥的了,感觉可以直接去掉scale_area(range = c(1, scl))这块。