diff --git a/_posts/ggplot2/2011-11-29-scale-x.Rmd b/_posts/ggplot2/2011-11-29-scale-x.Rmd index 0e37cb8b35c4..8fe10e3c4c12 100644 --- a/_posts/ggplot2/2011-11-29-scale-x.Rmd +++ b/_posts/ggplot2/2011-11-29-scale-x.Rmd @@ -41,6 +41,7 @@ packageVersion('plotly') ```{r, results='hide'} library(plotly) +library(scales) x <- c("04-01-10","05-01-10","06-01-10","07-01-10","08-01-10","09-01-10","10-01-10","11-01-10","12-01-10","01-01-11","02-01-11","03-01-11","04-01-11","05-01-11","06-01-11","07-01-11","08-01-11","09-01-11","10-01-11","11-01-11","12-01-11","01-01-12","02-01-12","03-01-12","04-01-12","05-01-12","06-01-12") y <- c(120,210,130,160,190,210,80,70,110,120,140,160,130,200,110,180,210,200,90,60,100,100,120,170,100,180,120) @@ -55,7 +56,7 @@ MySample$date <- as.Date(MySample$x, "%m-%d-%y") MySample$year <- year(MySample$date) p <- ggplot(MySample, aes(date, y, fill = year)) + - geom_bar(y=y,stat="identity") + + geom_bar(stat="identity") + facet_grid(. ~ year, scales = "free") + scale_x_date(labels = date_format("%b/%y")) + scale_fill_gradient(breaks=unique(MySample$year)) @@ -64,7 +65,7 @@ p <- ggplotly(p) # Create a shareable link to your chart # Set up API credentials: https://plot.ly/r/getting-started -chart_link = plotly_POST(p, filename="scalex/month") +chart_link = api_create(p, filename="scalex/month") chart_link ``` @@ -77,6 +78,7 @@ Inspired by Inspired by Stack Overflow. ## By Year @@ -104,6 +79,7 @@ Inspired by