Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jirlong committed May 27, 2024
1 parent 2bc5713 commit a959e54
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 2 additions & 2 deletions R04_5 ggplotly.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ NW.plot <- NW %>%
x = "Year",
y = "Net Worth") + th
ggplotly(NW.plot) %>%
ggplotly(NW.plot)
config(displayModeBar = FALSE)
```

Expand All @@ -75,7 +75,7 @@ NW.plot <- NW %>%
text = paste0("<b>年(X): </b>", year, "<br>",
"<b>淨資產(Y): </b>", Net_Worth,"<br>",
"<b>年齡組: </b>", Category),
group=1) +
group=Category) +
geom_line() +
theme_minimal() +
labs(title = "Net Worth by year grouped by age groups",
Expand Down
25 changes: 18 additions & 7 deletions R04_6 gganimate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,34 @@ pml <- read_excel("data/WORLD-MACHE_Gender_6.8.15.xls", "Sheet1", col_names=T) %
2. **`wmap <- fortify(wmap)`**: 使用**`fortify()`**函數將地圖的地理資料轉換為ggplot2套件可以理解的格式。這一步將地理資料轉換為一個資料框(data frame),其中每一行對應地圖上的一個多邊形區域。

```{r get-worldmap}
# install.packages("rgdal")
library(sf)
library(rworldmap)
wmap <- getMap(resolution="low")
wmap <- spTransform(wmap, CRS("+proj=robin")) # reproject
wmap <- fortify(wmap)
wmap %>%
filter(!duplicated(id))
data("countriesLow", package = "rworldmap")
countries_sf <- st_as_sf(countriesLow)
countries_sf_robinson <- st_transform(countries_sf, crs = "+proj=robin")
ggplot(data = countries_sf_robinson) +
geom_sf() +
theme_minimal()
```

```{r join-map-data}
pml_map <- wmap %>%
left_join(pml, by=c("id"="country")) %>%
pml_map <- countries_sf_robinson %>%
left_join(pml, by="ISO3") %>%
filter(!is.na(ISO3)) %>%
mutate(year = as.integer(year))
# devtools::install_github("thomasp85/transformr")
pml_map %>%
select(id) %>%
select(ISO3) %>%
filter(!duplicated(.))
```

Expand All @@ -60,10 +70,11 @@ pml_map %>%
pml_map %>%
filter(year==1995) %>%
ggplot() +
aes(x = long, y = lat,
group=group, fill=factor(degree)) +
geom_polygon(color="grey") +
theme_void() +
aes(x = LON, y = LAT,
fill=factor(degree)) +
geom_sf() +
theme_minimal()
# theme_void() +
scale_fill_manual(values=c("1"="red",
"2"="LightCyan",
"3"="lightskyblue",
Expand Down
14 changes: 11 additions & 3 deletions R05_3p_tm_typhoon.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ news.df %>%
# tf_idf

```{r}
unnested.df %>%
tf_idf <- unnested.df %>%
group_by(word) %>%
filter(n() > 10) %>%
ungroup() %>%
Expand All @@ -162,6 +162,14 @@ unnested.df %>%
arrange(-tf_idf) %>%
slice(1:15) %>%
ungroup() %>%
left_join(news.df %>% select(doc_id, title)) %>% View
left_join(news.df %>% select(doc_id, title))
```

```{r}
tf_idf %>%
group_by(doc_id) %>%
arrange(-tf_idf) %>%
slice(1:5) %>%
ungroup() %>%
count(word, sort = T)
```
10 changes: 6 additions & 4 deletions R24_categorical_data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ dt <- raw %>%
```

```{r}
dt$QA3[1:10]
as.integer(dt$QA3[1:10])
dt$QA3_lv[1:10]
as.integer(dt$QA3_lv[1:10])
```

### Excluding {#excluding}

如果有某些類別變數的值(如「拒答」)不想被編入`factor`,可以在`reorder()`中加入`exclude`的參數指定不想被編入類別值。
如果有某些類別變數的值(如「拒答」)不想被編入`factor`,可以在`order()`中加入`exclude`的參數指定不想被編入類別值。

```
mutate(QASide=ordered(QASide,
Expand Down Expand Up @@ -154,14 +154,16 @@ dt2 %>% count(Q7_3rd_lv)
- 連續性係數(Contingency Coeff.)和克拉瑪爾V(Cramer's V)的值,表示兩個變數之間的關聯性較弱,但仍存在一定程度的相關性。

```{r}
(xtb <- xtabs(~QA3_lv + Q7_3rd_lv, data=dt2))
(chi2 <- chisq.test(xtb))
vcd::assocstats(xtb)
print(round(chi2$observed, 2))
print(round(chi2$expected, 2))
print(round(chi2$residuals, 2))
```

```{r}
Expand Down

0 comments on commit a959e54

Please sign in to comment.