我有一个工作代码,它引用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))
我想要做的是使aes
中的大小变量引用FIRST
函数之外指定的SECOND
和geom_point
变量。鉴于geom_point()
结构,这是否可行?