mapdata
csv ( ) を参照して、米国の地図の上に 2 セットのデータをプロットする作業コードがあります。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){.....
など、結果として 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()