ggplot

ルート探索

# 必要なライブラリのロード library(tidyverse) library(sf) library(mapview) library(stplanr) library(OpenStreetMap) # 2地点間のポイントデータ作成 sfd = tribble(~lat,~lon,~location, 36.075411, 136.212213,"福井大学", 36.062244, 136.223214, "…

sfオブジェクトをggplot()する場合はgeometryカラムの名前に注意

geom_sf()関数を利用するにあたり geometryカラムがgeometryではなくgeomの場合にはエラーが出た。 解決方法のメモ。 library(sf) library(ggplot2) library(spData) data(world) head(world) Simple feature collection with 6 features and 10 fields geom…

ggplot2でグループごとの図を出力する

ggplotでグループごとに図を出力したい場合がある。 意外と簡単な方法でできるのでメモ。 stackoverflow.com library(ggplot2) library(dplyr) res <- iris %>% group_by(Species) %>% do( plots= ggplot(data=.) + geom_point(aes(Sepal.Length, Petal.Leng…

ggpairs()できれいなペアプロット

pairs()をggplot2風に書けるらしい。 library(tidyverse) library(GGally) iris %>% GGally::ggpairs(data = ., aes(color = Species)) 美しいペアプロット図を簡単に作る