2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

R言語のecotourismパッケージの紹介

Last updated at Posted at 2025-09-22

R言語のecotourismパッケージが興味深かったのでご紹介。
2025年09月16日に0.1.0がリリースされたばかりの新しいパッケージです。

オーストラリアの野生生物、気象、観光のデータを含むデータセット集で、従来のnycflights13Lahmanと同じように、関連を持った複数のデータテーブル(Rの場合はデータフレーム)を含み、デモデータとしてデータの操作や可視化の練習などに使えます。
nycflights13Lahmanと異なるのは地理空間上でのデータ操作を簡単に試せることです。

まずはやってみましょう。

library(conflicted) # 関数名の衝突予防
library(tidyverse)  # モダンなデータ操作
library(ecotourism) # 今回紹介するパッケージ
library(ggthemes)   # ggplot2のテーマ集。theme_map()を使いたいため。
library(ggrepel)    # 可視化のラベルの重複回避用

ecotourismパッケージにはオーストラリアの地図のデータoz_lgaが含まれるため、簡単にオーストラリアの地図を描くことができます。これは地方政府地域(LGA)単位のポリゴンデータでsfオブジェクトとなっています。

ggplot() +
  geom_sf(data = oz_lga) +
  theme_map()

01.png

簡単ですね!

緯度経度で指定すれば一部にズームインすることも簡単です。タスマニア島に注目してみましょう。

ggplot() +
  geom_sf(data = oz_lga) +
  theme_map() +
  coord_sf(
    xlim = c(144, 149), # 経度の範囲
    ylim = c(-44, -40), # 緯度の範囲
    expand = FALSE
  )  

02.png

ecotourismパッケージには9つのデータセットが含まれており、それぞれの関係は以下のER図のようになっています。

image.png

  • 野生生物の観測データ
    • glowworms: ツチボタルの観測データ(2014–2024)
    • gouldian_finch: コキンチョウの観測データ(2014–2024)
    • manta_rays: ナンヨウマンタの観測データ(2014–2024)
    • orchids: ラン科の植物の観測データ(2014–2024)
  • top_stations: それぞれの野生生物の主要気象観測所
  • weather_data: 主要気象観測所の日次の気象データ(2014–2024)
  • weather_stations: 気象観測所のマスターデータ
  • tourism_quarterly: 四半期ごとの旅行者数と旅行目的
  • tourism_region: オーストラリアの観光地域情報(緯度経度付き)

先ほどの地図に情報を載せてみましょう。
ツチボタルの観測地はこうなります。

glowworms |>
  ggplot() +
  geom_sf(data = oz_lga) +
  geom_point(aes(x = obs_lon, y = obs_lat), color = "red", alpha=0.2) +
  theme_map()

image.png
おや、生息地がトーストラリア東部とタスマニア島の2か所に分かれているようです。

このデータには種の情報も入っているので、種によって色を分けてみましょう。

glowworms |> 
  ggplot() +
  geom_sf(data = oz_lga) +
  geom_point(aes(x = obs_lon, y = obs_lat, color = sci_name, shape = sci_name), alpha=0.3) +
  theme_map()

image.png
どうやら種によって生息地域が分かれているようです。

タスマニア島にズームインしてみます。

glowworms |> 
  ggplot() +
  geom_sf(data = oz_lga) +
  geom_point(aes(x = obs_lon, y = obs_lat, color = sci_name, shape = sci_name), alpha=0.3) +
  coord_sf(
    xlim = c(144, 149),  # 経度の範囲
    ylim = c(-44, -40), # 緯度の範囲
    expand = FALSE
  ) +
  theme_map()

image.png

何か所かに集中している様子ですね。
ツチボタルですから洞窟のある場所でしか観測できないんでしょう(たぶん)。

マンタのデータではどうでしょうか。

manta_rays |> 
  ggplot() +
  geom_sf(data = oz_lga) +
  geom_point(aes(x = obs_lon, y = obs_lat), shape = 21, color = "blue", fill = "blue", alpha=0.3) +
  theme_map()

image.png
当然ながら海沿いに分布していますね。

観光のデータの方も見てみましょう。
tourism_quarterlyには四半期ごとの観光地の旅行者数と目的が入っています。これには緯度経度の情報が入っていないので、観光地の緯度経度の情報を含むtourism_regionとjoinします。

tourism_2014_1q <- tourism_quarterly |>
  # 期間を2014年の第1四半期に絞る
  dplyr::filter(year == 2014, quarter == 1) |> 
  inner_join(tourism_region, by = join_by(region_id, ws_id))

ggplot() +
  geom_sf(data = oz_lga) +
  geom_point(data = tourism_2014_1q, aes(x = lon, y = lat, size = trips, color = purpose, fill = purpose), shape = 21, alpha = 0.5) +
  theme_map() +
  labs(title = "地域ごとの旅行者数", subtitle = "旅行目的別") +
  facet_wrap(vars(purpose), ncol = 1)

image.png

観光が多い地域とビジネスが多い地域とがあるはずです。バランスを見てみましょう。

tourism_2014_1q_2 <- tourism_quarterly |>
  # 期間を2014年の第1四半期に絞る
  dplyr::filter(year == 2014, quarter == 1) |>
  inner_join(tourism_region, by = join_by(region_id, ws_id)) |>
  dplyr::select(region, purpose, trips) |>
  pivot_wider(names_from = purpose, values_from = trips) |>
  dplyr::mutate( #NAのゼロ埋め
    Holiday = replace_na(Holiday, 0),
    Business = replace_na(Business, 0),
    diff = (Business + 1) / (Holiday + 1)
    )

tourism_2014_1q_2 |>
  ggplot(aes(x = Holiday, y = Business, label = region)) +
  geom_point() +
  geom_label_repel() +
  scale_x_continuous(limits = c(0, 400)) +
  scale_y_continuous(limits = c(0, 400)) +
  coord_fixed()

image.png
観光もビジネスもシドニーとメルボルンがぶっちぎりですね。そりゃあそうか。

観光とビジネスの差が大きいエリアを探すため、比の大きさを確認します。

tourism_2014_1q_2 |>
  slice_max(diff, n = 3)
# # A tibble: 3 × 4
#   region      Holiday Business  diff
#   <chr>         <dbl>    <dbl> <dbl>
# 1 Meekatharra       0     53.0  54.0
# 2 Karratha          0     40.1  41.1
# 3 Newman            0     37.4  38.4

tourism_2014_1q_2 |>
  slice_min(diff, n = 3)
# # A tibble: 3 × 4
#   region                  Holiday Business   diff
#   <chr>                     <dbl>    <dbl>  <dbl>
# 1 Maclean - Yamba - Iluka    73.7        0 0.0134
# 2 Forster                    73.3        0 0.0135
# 3 Foster                     70.6        0 0.0140

観光客が来ないのは西部のMeekatharra、Karrathaといったエリアでいずれも鉱山の街のようです。
逆にビジネス客が来ないのはMaclean - Yamba - Ilukaという3つの街が隣接するクラレンス川の河口付近の地域で、スコットランドの文化が残る観光地のようです。

(2025/09/23追記)
気象データを使った事例を載せるのを忘れてました。
気象観測所ごとに気温、湿度、風速などのデータがあります。

ここではコキンチョウの観測数と雨の関係を見てみましょう。

top_stations |>
  dplyr::filter(organism == "gouldian_finch") |>
  inner_join(weather, by = join_by(ws_id)) |>
  dplyr::select(ws_id, date, rainy) |>
  left_join(gouldian_finch, by = join_by(ws_id, date)) |>
  mutate(obs = if_else(is.na(record_type), 0, 1)) |>
  dplyr::select(ws_id, date, rainy, obs) |>
  drop_na() |>
  summarise(n = sum(obs), .by = c(ws_id, rainy)) |>
  left_join( #観測所名
    weather_stations |> dplyr::select(ws_id, stname),
    by = join_by(ws_id)
    ) |>
  ggplot(aes(x = stname, y = n, fill = as.factor(rainy))) +
  geom_col(position = "dodge") +
  labs(title = "天候とコキンチョウの観測数", y = "観測数", x = "最寄りの気象観測所", fill = "雨か否か")

image.png
やはり、雨の日はコキンチョウの観測数が極端に少なくなる傾向がありそうですね。

以上、簡単ですがecotourismパッケージの紹介でした。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?