5/29/2020

Data Creation

First we create a bunch of random data

x <- rnorm(150, 30, 2)
y <- log(x)*sin(x)
tag <- rep(c("A", "B", "C"), 50)
c <- sample(c(2,4,6), 150, replace = T)
df <- data.frame(x = x, y = y, tag = tag, c = c)
head(df)
##          x          y tag c
## 1 29.80847 -3.3925123   A 6
## 2 31.28202 -0.4596527   B 6
## 3 32.32814  2.7489767   C 2
## 4 28.66932 -1.2912988   A 4
## 5 27.63243  1.9871474   B 2
## 6 29.07962 -2.4298976   C 2

GGplot

Then a ggplot is created

suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(plotly))
g <- ggplot(data = df, aes(x = x, y = y)) +
    geom_line() + facet_grid(c~tag)

Plotly

ggplotly(g)