2021320303 정지원
1번
library(dplyr)
library(ggplot2)
iris2 <- cbind(as.data.frame(as.integer(rownames(iris))), iris)
colnames(iris2)[1] <- "Num"
group <- colnames(iris2)[2:5]
g <- iris2 %>% ggplot(aes(x=Num))
g <- g + geom_line(aes(y=Sepal.Length, color=group[1], linetype=group[1]))
g <- g + geom_line(aes(y=Sepal.Width, color=group[2], linetype=group[2]))
g <- g + geom_line(aes(y=Petal.Length, color=group[3], linetype=group[3]))
g <- g + geom_line(aes(y=Petal.Width, color=group[4], linetype=group[4]))
g <- g + scale_color_manual(values = 1:4, breaks = group)
g <- g + scale_linetype_manual(values = 1:4, breaks = group)
g <- g + theme_classic()
g <- g + theme(legend.position = c(0.118, 0.85), legend.direction = "vertical", legend.title = element_blank(), legend.background = element_rect(linetype = "solid", color = "black"))
g <- g + labs(x = "", y = "iris[, 1:4]")
g
Plot 결과물
2번
library(tm)
library(XML)
library(wordcloud2)
library(SnowballC)
library(RCurl)
library(KoNLP)
t =readLines('<https://ko.wikipedia.org/wiki/%ED%86%B5%EA%B3%84%ED%95%99>')
d = htmlParse(t, asText = TRUE)
clean_doc = xpathSApply(d, "//p", xmlValue)
doc = Corpus(VectorSource(clean_doc))
doc = tm_map(doc, content_transformer(tolower))
doc = tm_map(doc, removeNumbers)
doc = tm_map(doc, removePunctuation)
doc = tm_map(doc, stripWhitespace)
for (i in 1:length(doc)) doc[[i]]$content <- extractNoun(doc[[i]]$content)
dtm = DocumentTermMatrix(doc)
dim(dtm)
m = as.matrix(dtm)
v=sort(colSums(m), decreasing = T)
d = data.frame(word = names(v), freq=v)
d <- d[nchar(as.character(d$word)) > 1, ]
d100 = d[1:100, ]
wordcloud2(d100)
불용어 처리: 기본적으로 KoNLP의 extractNoun 함수를 사용하였고, 이후 1글자 단어는 전부 제외시켰다. 1글자 단어를 제외시키지 않았을 때, ‘한’, ‘적’, ‘등’, ‘것’, ‘들’과 같이 크게 의미를 가지지 않는 것으로 보여서 이를 제외하고 wordcloud를 만들었다.
Plot 결과물