manipulate関数の書き方``
manipulate(
実行スクリプト,
picker, sliderの情報(複数の場合はカンマで結合)
)
manipulate(
{
複数の実行スクリプト
},
picker, sliderの情報(複数の場合はカンマで結合)
)
注意:manipulate関数は、配布Notebookファイルではなく、拡張子”.R”のファイル上で確認すること
ライブラリのインストール
install.packages("manipulate")
ライブラリの読み込み
library(manipulate)
色の選択
title<-"PCH Symbols"
xlabel="x"
ylabel="y"
plot(0,1,pch=8,cex=5,col="blue", main=title, xlab=xlabel, ylab=ylabel)

manipulate(plot(0,0,pch=8,cex=5,col=myColors), myColors=picker("red", "violet", "pink", "orange", "yellow", "green", "blue", "cyan") )
プロットマーカーの選択
manipulate(
plot(0,0,pch=myMarkers,cex=5,col=myColors), myColors=picker("red", "violet", "pink", "orange", "yellow", "green", "blue", "cyan",initial="violet"),
myMarkers=picker(1,2,3,4,5,6,7,8,initial="5")
)
picker + List
colPalets = c("red", "violet", "pink", "orange", "yellow", "green", "blue", "cyan")
manipulate(
plot(0,0,pch=myMarkers,cex=5,col=myColors, main=title, xlab=xlabel, ylab=ylabel),
myColors=picker(as.list(colPalets),initial=colPalets[2]),
myMarkers=picker(as.list(seq(1,8)),initial="5")
)
プロットサイズの選択
manipulate(
plot(0,0,pch=8,cex=mySize,col="blue"),
mySize=slider(1,10,initial=5,step=2)
)
軸ラベル表示の選択
manipulate(
plot(0,0,pch=8,cex=mySize,col="blue", ann=annFlag, ylab="Y axis",xlab="X axis"),
mySize=slider(1,11,initial=5,step=2),
annFlag = checkbox(FALSE, "Show Label")
)
オンライン記事から情報を取得 (Ref. Lec02)
ライブラリの読み込み
library(httr)
library(rvest)
# URL of the Mainichi Shinbun's article
url <- "https://mainichi.jp/english/articles/20241106/p2g/00m/0in/002000c"
# Send a GET request with a user agent
response <- GET(url, user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15"))
page <- read_html(response)
Text Cleaning
#cleaned_content <- gsub("\\r|\\n", "", article_content)
cleaned_content <- trimws(article_content)
cleaned_content <- paste(cleaned_content, collapse = "")
substring(cleaned_content, 1, 100)
[1] "WASHINGTON (AP) -- A divided America weighed a stark choice for the nation's future Tuesday as a pre"
出現単語頻度表の作成(高頻度順)
wordLst<-strsplit(cleaned_content,"[[:space:]]|[[:punct:]]")
wordLst<-unlist(wordLst)
wordLst<-tolower(wordLst)
wordLst<- wordLst[wordLst != ""]
freq <- table(wordLst)
freq_data<-sort(freq, decreasing=TRUE)
paste("Tokens", sum(freq_data), sep = ": ")
paste("Types", length(freq_data), sep = ": ")
length(sub_freq_data)
[1] 30
las = 0 : XYの両軸とも目盛り文字は軸方向(デフォルト)
las = 1 : XYの両軸とも目盛り文字は水平方向
las = 2 : XYの両軸とも目盛り文字は軸方向と直角
las = 3 : XYの両軸とも目盛り文字は垂直方向
barplot(sub_freq_data, las=3,col=colPalets,ylab="Frequency")
