R Markdownでの諸々のテスト
ちょっとRの出力を色々試してみたいと思います。
コードと出力について
collapseで表(data.frame)をそのまま出力。
x <- iris %>% 
  select(starts_with("S")) %>% 
  group_by(Species) %>% 
  head()
x
#>  # A tibble: 6 x 3
#>  # Groups:   Species [1]
#>    Sepal.Length Sepal.Width Species
#>           <dbl>       <dbl>  <fctr>
#>  1          5.1         3.5  setosa
#>  2          4.9         3.0  setosa
#>  3          4.7         3.2  setosa
#>  4          4.6         3.1  setosa
#>  5          5.0         3.6  setosa
#>  6          5.4         3.9  setosa
knitr::kable()を利用して表を出力。
knitr::kable(x)
| Sepal.Length | Sepal.Width | Species | 
|---|---|---|
| 5.1 | 3.5 | setosa | 
| 4.9 | 3.0 | setosa | 
| 4.7 | 3.2 | setosa | 
| 4.6 | 3.1 | setosa | 
| 5.0 | 3.6 | setosa | 
| 5.4 | 3.9 | setosa | 
plotについて
簡単なものでテスト。
ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point()

htmlwidgets系のテスト
やってみる。
leaflet
library(leaflet)
leaflet() %>% 
  addTiles() %>% 
  addMarkers(lng = 135.0000, lat = 35.0000)
DiagrammeR
公式ドキュメントにあるサンプルから。
library(DiagrammeR)
grViz("
digraph a_nice_graph {
# node definitions with substituted label text
node [fontname = Helvetica]
a [label = '@@1']
b [label = '@@2-1']
c [label = '@@2-2']
d [label = '@@2-3']
e [label = '@@2-4']
f [label = '@@2-5']
g [label = '@@2-6']
h [label = '@@2-7']
i [label = '@@2-8']
j [label = '@@2-9']
# edge definitions with the node IDs
a -> {b c d e f g h i j}
}
[1]: 'top'
[2]: 10:20
")
Plotly
公式サイトにある例から一部修正して。
library(plotly)
#>  
#>   次のパッケージを付け加えます: 'plotly'
#>   以下のオブジェクトは 'package:ggplot2' からマスクされています: 
#>  
#>       last_plot
#>   以下のオブジェクトは 'package:stats' からマスクされています: 
#>  
#>       filter
#>   以下のオブジェクトは 'package:graphics' からマスクされています: 
#>  
#>       layout
p <- ggplot2::diamonds[sample(nrow(diamonds), 5000),] %>% 
  plot_ly(y = ~price, color = ~cut, type = "box")
p
ひとますはこの辺で。だいたいいけそうです。