Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ggplot2那里有个问题 #1

Open
ghkk opened this issue Aug 25, 2015 · 1 comment
Open

ggplot2那里有个问题 #1

ghkk opened this issue Aug 25, 2015 · 1 comment

Comments

@ghkk
Copy link

ghkk commented Aug 25, 2015

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)
}

我还是新手,后面的画图直接拷贝的、、、

@hetong007
Copy link
Owner

好像因为ggplot2版本更迭我已经查不到range这个参数是干啥的了,感觉可以直接去掉scale_area(range = c(1, scl))这块。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants