Skip to content

Commit

Permalink
add ggplot2 code to fix the lack of captioning code that plotly lacks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuyib committed Feb 10, 2019
1 parent 282f5a7 commit a09828f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 13 additions & 0 deletions YT_dataviz.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
16 changes: 12 additions & 4 deletions shiny-time-series/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,32 @@ df2 <- read_csv('data/exotic_yt_date.csv')
# date and any other variables that follow which i presume will be in the y axis

# starter code for the plot
ggplot(df, aes(date, subscribers_gained)) + geom_area() + geom_line()
p1 <- ggplot(df, aes(date, subscribers_gained)) + geom_line() + geom_area(fill = "red") +
xlab("Date") + ylab("Views") + labs(caption = "Sliceace channel")

# Using pipes
df %>% ggplot(aes(date, subscribers_gained)) + geom_line() + geom_area()
p2 <- df2 %>% ggplot(aes(date, subscribers_gained)) + geom_line() + geom_area(fill = "green") +
xlab("Date") + ylab("Views") + labs(caption = "James channel")


# joining the plots to appear side by side
grid.arrange(p1,p2, ncol = 2)

# Make a function that will allow you to call a different variable in the y axis
# adding ggplotly functionality
# redo exercise to fix this
# fix the title or add a subtitle to distinguish the plots
choose_y_axis_plot <- function(dataframe, yaxis = readline(), dataframe2, yaxis2 = readline()) {
# define variable p1 with ggplot specifications for the first plot
p1 <- ggplot(dataframe, aes(date, yaxis)) + geom_line() + geom_area(fill = "green") +
p1 <- ggplot(dataframe, aes(date, yaxis)) + geom_area(fill = "green") +
xlab("Date") + ylab("Views") + labs(caption = "Sliceace channel")

# for the second plot
p2 <- ggplot(dataframe2, aes(date,yaxis2)) + geom_line() + geom_area(fill = "red") +
p2 <- ggplot(dataframe2, aes(date,yaxis2)) + geom_area(fill = "red") +
xlab("Date") + ylab("Views") + labs(caption = "James channel")

# joining the plots together with regular ggplot2

# convert the plots to plotly plots this is how it's done
plot_p1 <- ggplotly(p1)
plot_p2 <- ggplotly(p2)
Expand Down

0 comments on commit a09828f

Please sign in to comment.