Getting Started With R

This article can act as a starting point for any basic R article, with a coding cell and a setup cell in the Appendix. Just Remix and go!

3.5s
Language:R
library(plotly)

# Plotly scatterplot
plot_ly(data = iris, x = ~Petal.Width, y = ~Petal.Length, 
        type = "scatter", mode = "markers") %>%
  layout(title="Iris Petal Length",
         xaxis = list(title = "x"),
         yaxis = list(title = "f(x)")
        )

# GGPlot hist
ggplot(data=iris, aes(iris$Sepal.Length)) + geom_histogram() + 
  labs(title="Iris Data", 
         x="Iris sepal length", 
         y="")

# R built-in pairs() scattermatrix
pairs(~Sepal.Length+Sepal.Width+Petal.Length+Petal.Width, data=iris,
      main="Scatterplot Matrix")

# And some text analysis to a table
library(dplyr)
library(janeaustenr)
library(tidytext)

book_words <- austen_books() %>%
  unnest_tokens(word, text) %>%
  count(book, word, sort = TRUE) %>%
  ungroup()

total_words <- book_words %>% 
  group_by(book) %>% 
  summarize(total = sum(n))

book_words <- left_join(book_words, total_words)

book_words
© 2018 Nextjournal GmbH