그래서 Wikipedia의 데이터를 사용하여 그래프를 만들고 싶습니다. 찾은 테이블에서 데이터 프레임을 만들었습니다. 여기에는 맥주 스타일과 "20-50"과 같은 다양한 간수 (IBU)라는 두 개의 열이 있습니다. 둘 다 캐릭터이기 때문에 이치에 맞는 그래프를 만들 수 없습니다. IBU 열을 숫자 (최소 및 최대) 인 두 개의 개별 열로 변경했지만 첫 번째 데이터 프레임 안에 두 번째 데이터 프레임을 만들고 비슷한 경우를 찾으려고했지만 할 수 없었습니다. 이제 막혔습니다. t 다음에 무엇을해야할지 알아요 :( 너무 많은 코드를 붙여 넣어서 미안합니다. 누군가가 데이터를 읽고 그 구조를 보길 원합니다.
library(xml2)
library(rvest)
library(ggplot2)
library(tidyr)
file_html <- read_html(
"https://pl.wikipedia.org/wiki/International_Bittering_Units",
encoding = "UTF-8")
table_html <- html_node(file_html, "#mw-content-text > div > table")
table_IBU <- html_table(table_html, fill = TRUE)
table_IBU$IBU2 <- str_replace(table_IBU$`Stopień IBU`, "\\+", "")
table_IBU$IBU3 <- tidyr::separate(table_IBU, IBU2, into = c("min", "max"), sep = " – ")
table_IBU <- subset(table_IBU, select = -c(IBU2,
`Stopień IBU`,
`Gatunek piwa`))
table_IBU$IBU3$min2 <- as.numeric(table_IBU$IBU3$min)
table_IBU$IBU3$max2 <- as.numeric(table_IBU$IBU3$max)
#graph that I can come up with on my own
IBUgraph <- ggplot(table_IBU$IBU3, aes(reorder(`Gatunek piwa`, + max2),
max2)) +
geom_point(width = 0.5, color = "darkolivegreen",
fill = "darkseagreen4") +
theme(text=element_text(size = 9))
IBUgraph = IBUgraph +
labs(y = "Międzynarodowe Jednostki Goryczy (IBU)",
x = "Gatunek",
title = "Skala IBU - International Bitterness Units,
czyli międzynarodowe jednostki goryczy")
IBUgraph <- IBUgraph + theme(axis.text.x=element_text(angle=45, hjust=1.1))
IBUgraph
결국 나는 x 축에 맥주 스타일을 보여주는 ggplot ()과 최소값, 최대 값을 보여주는 각 스타일에 대해 두 점을 사용하여 그래프를 만들고 싶습니다.
예를 들어 덤벨 차트라고합니다.
ggplot(table_IBU$IBU3,aes(x=`Gatunek piwa`)) +
geom_point(aes(y=min2)) + # add point for min
geom_point(aes(y=max2)) + # add point for max
geom_segment(aes(xend=`Gatunek piwa`,y=min2,yend=max2)) + # create segment between min and max
theme(axis.text.x = element_text(angle = 90, hjust = 1)) # rotate x axis
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다