데이터 시각화
그래프에서 하이라이트 적용하기(gghighlight)
r-code-for-data-analysis
2023. 5. 29. 09:36
여러 선들이 겹쳐있을 때 내가 중요하게 보는 것만 강조해서 보여주는 패키지가 "gghighlight" 이다.
https://yutannihilation.github.io/gghighlight/
Highlight Lines and Points in ggplot2
Make it easier to explore data with highlights.
yutannihilation.github.io
그러면 아래와 같이 여러개 선들 중 중요하게 보여주고 싶은 것만 색을 칠할 수 있다.
1. 패키지 설치 및 불러오기
install.packages("gghightligt")
library(gghighlight)
2. 데이터 만들기
set.seed(2)
d <- purrr::map_dfr(
letters,
~ data.frame(
idx = 1:400,
value = cumsum(runif(400, -1, 1)),
type = .,
flag = sample(c(TRUE, FALSE), size = 400, replace = TRUE),
stringsAsFactors = FALSE
)
)
head(d)
3. 그래프 그리기
ggplot(d) +
geom_line(aes(idx, value, colour = type)) +
gghighlight(max(value) > 17)
ggplot(d) +
geom_line(aes(idx, value, colour = type)) +
gghighlight(max(value) > 17) +
theme_minimal()
ggplot(d) +
geom_line(aes(idx, value, colour = type)) +
gghighlight(max(value) > 17) +
theme_minimal() +
facet_wrap(~ type)
728x90
반응형