我有引用 csv ( mapdata
) 的工作代码来在美国地图上绘制两组数据。我有兴趣构建一个用户输入,该输入允许用户运行脚本来选择他们想要在地图上绘制的数据列,并geom_point()
相应地更新命令。
我一直在使用as.numeric
并对readline()
每组数据的请求进行分类
# select the first variable to use:
selectFIRST <- function() {
as.numeric(readline("Please enter a number to select the first: \n 1-Clinical_Trial\n 2- Comparative_Study\n 3-Evaluation_Studies\n 4-In_Vitro\n 5- JOURNAL_ARTICLE\n 6-Consensus_Development_Conference\n 7-Guideline\n 8-Research_Support_NonUSGovt\n 9-Total>>> "))
}
Input_First <- selectFIRST()
print(Input_First)
# define the first variable based on numeric input
First <- "error"
if(Input_First == 1){
First <- 'Clinical_Trial'
} else if(Input_First == 2){.....
依此类推,产生两个变量 (First
和Second
)。然后我定义
all_states <- map_data("state")
g <- ggplot()
g <- g + geom_polygon(data=all_states, aes(x=long, y=lat, group = group),
colour="grey", fill="white" )
print(g)
plot.new()
mapPoints <- g + geom_point(data = mapdata,
aes(x=lon, y=lat, size = [FIRST or SECOND]),
color = "#1100e7", bg = "#43c9e7", alpha = .75,
shape = 21) + scale_size(range=c(3,15))
我想做的是使 size 变量内部aes
引用函数外部指定的FIRST
和变量。考虑到结构,这可能吗?SECOND
geom_point
geom_point()