데이터 시각화 어디까지 보고 오셨어요?
한국 R 사용자회
2024년 6월 25일
데이터 시각화 (이광춘, 2018)
데이터 시각화 + 저널리즘
데이터 시각화 + 저널리즘 + 챗GPT
ggplot
데이터 시각화
질의응답!
2023년 챗GPT 데이터 사이언스
2024년 인공지능 데이터 사이언스
gm_highlight <- highlight_key(gapminder,
~country)
life_g <- gm_highlight %>%
ggplot(aes(
x=year,
y=lifeExp,
group=country,
text=paste0("대륙: ", continent, "\n",
"국가: ", country))) +
geom_line()
life_gg <- ggplotly(life_g, tooltip = "text")
highlight(life_gg, on = "plotly_click",
selectize = TRUE,
dynamic = TRUE,
persistent = TRUE)
gapminder_cjk <- gapminder %>%
filter(country %in% c("China", "Japan",
"Korea, Rep."))
gapminder_sd <- SharedData$new(gapminder_cjk,
~country)
life_g <- gapminder_sd %>%
ggplot(aes(
x = year,
y = lifeExp,
group = country,
text = paste0("대륙: ", continent, "\n",
"국가: ", country))) +
geom_line() +
geom_point() +
facet_wrap(~country)
ggplotly(life_g, tooltip = "text")
library(crosstalk); library(DT)
### 1. 공유 데이터
general_sd_df <- general_df %>% select(삼국, 무장, 무력, 지력, 통솔, 생년)
sam_sd <- SharedData$new(general_sd_df)
### 2. 제어
sam_ctrl <- filter_checkbox("삼국", "위촉오", sam_sd, ~삼국, inline = TRUE)
year_ctrl <- filter_slider("생년", "출생년도", sam_sd, ~생년, width = "50%")
### 3. 표
sam_tbl <- sam_sd |>
datatable( extensions="Scroller", style="bootstrap", class="compact", width="100%",
options=list(deferRender=TRUE, scrollY=300, scroller=TRUE))
### 4. 시각화
force_g <- ggplot(sam_sd, aes(x=무력, y=통솔, color=삼국,
text = paste('이름 :', 무장, "\n",
'무력:', 무력, "\n",
'지력:', 지력, "\n",
'통솔:', 통솔, "\n"))) +
geom_point() +
theme(legend.position = "none") +
labs(x="무력", y="통솔") +
scale_color_manual(values = c("red", "green", "blue"))
force_gg <- ggplotly(force_g, tooltip = "text")
### 5. 인터랙티브 시각화
bscols(widths = c(2, 5, 5),
list(year_ctrl, sam_ctrl),
sam_tbl, force_gg)
library(tidyverse)
library(gapminder)
library(plotly)
life_g <- gapminder %>%
ggplot(aes(
x = gdpPercap,
y = lifeExp,
group = country, color=country,
text=paste0("대륙: ", continent, "\n",
"국가: ", country))) +
geom_point(alpha = 0.2) +
geom_point() +
facet_wrap(~continent, ncol = 2) +
scale_x_sqrt() +
theme(legend.position = "none")
ggplotly(life_g, tooltip="text")
frame= 매개변수
만 넣으면 됨.
library(tidyverse)
library(gapminder)
library(plotly)
life_g <- gapminder %>%
ggplot(aes(
x = gdpPercap,
y = lifeExp,
group = country, color=country,
text=paste0("대륙: ", continent, "\n",
"국가: ", country))) +
geom_point(alpha = 0.2) +
geom_point(aes(frame = year), color="red") +
facet_wrap(~continent, ncol = 2) +
scale_x_sqrt() +
theme(legend.position = "none")
ggplotly(life_g, tooltip="text")
crosstalk
library(crosstalk); library(plotly); library(leaflet); library(palmerpenguins)
penguins <- na.omit(penguins) # Remove missing data for simplicity
penguins$longitude <- rnorm(nrow(penguins), mean = -64, sd = 0.1)
penguins$latitude <- rnorm(nrow(penguins), mean = -64, sd = 0.1)
# Create a shared data object
sd_penguins <- SharedData$new(penguins)
# Plot with plotly
penguin_plot <- plot_ly(sd_penguins, x = ~bill_length_mm, y = ~flipper_length_mm,
color = ~species,
text = ~paste("Body Mass:", body_mass_g),
type = 'scatter', mode = 'markers') %>%
add_markers() %>% highlight("plotly_selected")
# Map with leaflet
penguin_map <- leaflet(sd_penguins) %>% addTiles() %>%
addCircles(lng = ~longitude, lat = ~latitude,
weight = 1, radius = 40, popup = ~species)
# Combine both using crosstalk
bscols(widths = c(6, 6), penguin_plot, penguin_map)
crosstalk