Skip to content

Commit a3723e7

Browse files
authored
Merge pull request #1115 from plotly/scale-x-errors
update scale-x-date example to work
2 parents 4f242e4 + 874f554 commit a3723e7

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

_posts/ggplot2/2011-11-29-scale-x.Rmd

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ packageVersion('plotly')
4141

4242
```{r, results='hide'}
4343
library(plotly)
44+
library(scales)
4445
4546
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")
4647
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")
5556
MySample$year <- year(MySample$date)
5657
5758
p <- ggplot(MySample, aes(date, y, fill = year)) +
58-
geom_bar(y=y,stat="identity") +
59+
geom_bar(stat="identity") +
5960
facet_grid(. ~ year, scales = "free") +
6061
scale_x_date(labels = date_format("%b/%y")) +
6162
scale_fill_gradient(breaks=unique(MySample$year))
@@ -64,7 +65,7 @@ p <- ggplotly(p)
6465
6566
# Create a shareable link to your chart
6667
# Set up API credentials: https://plot.ly/r/getting-started
67-
chart_link = plotly_POST(p, filename="scalex/month")
68+
chart_link = api_create(p, filename="scalex/month")
6869
chart_link
6970
```
7071

@@ -77,6 +78,7 @@ Inspired by <a href="http://stackoverflow.com/questions/11472856/month-year-bar-
7778

7879
```{r, results='hide'}
7980
library(plotly)
81+
library(scales)
8082
8183
set.seed(12345)
8284
Date <- seq(as.Date("2010/1/1"), as.Date("2014/1/1"), "week")
@@ -102,7 +104,7 @@ p <- ggplotly(p)
102104
103105
# Create a shareable link to your chart
104106
# Set up API credentials: https://plot.ly/r/getting-started
105-
chart_link = plotly_POST(p, filename="scalex/year")
107+
chart_link = api_create(p, filename="scalex/year")
106108
chart_link
107109
```
108110

_posts/ggplot2/2011-11-29-scale-x.md

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ packageVersion('plotly')
3535
```
3636

3737
```
38-
## [1] '4.5.6.9000'
38+
## [1] '4.8.0'
3939
```
4040

4141
## By Month
4242

4343

4444
```r
4545
library(plotly)
46+
library(scales)
4647

4748
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")
4849
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)
@@ -57,53 +58,28 @@ MySample$date <- as.Date(MySample$x, "%m-%d-%y")
5758
MySample$year <- year(MySample$date)
5859

5960
p <- ggplot(MySample, aes(date, y, fill = year)) +
60-
geom_bar(y=y,stat="identity") +
61+
geom_bar(stat="identity") +
6162
facet_grid(. ~ year, scales = "free") +
6263
scale_x_date(labels = date_format("%b/%y")) +
6364
scale_fill_gradient(breaks=unique(MySample$year))
64-
```
65-
66-
```
67-
## Error in check_breaks_labels(breaks, labels): could not find function "date_format"
68-
```
6965

70-
```r
7166
p <- ggplotly(p)
72-
```
7367

74-
```
75-
## Error in ggplotly(p): object 'p' not found
76-
```
77-
78-
```r
7968
# Create a shareable link to your chart
8069
# Set up API credentials: https://plot.ly/r/getting-started
81-
chart_link = plotly_POST(p, filename="scalex/month")
82-
```
83-
84-
```
85-
## Error in plotly_build(x): object 'p' not found
86-
```
87-
88-
```r
70+
chart_link = api_create(p, filename="scalex/month")
8971
chart_link
9072
```
9173

92-
```
93-
## Error in eval(expr, envir, enclos): object 'chart_link' not found
94-
```
95-
96-
97-
```
98-
## Error in eval(expr, envir, enclos): object 'chart_link' not found
99-
```
74+
<iframe src="https://plot.ly/~bdun9/3363.embed" width="800" height="600" id="igraph" scrolling="no" seamless="seamless" frameBorder="0"> </iframe>
10075
Inspired by <a href="http://stackoverflow.com/questions/11472856/month-year-bar-graph-plot-faceted-and-filled-on-year-with-data-input-as-date-in?rq=1">Stack Overflow</a>.
10176

10277
## By Year
10378

10479

10580
```r
10681
library(plotly)
82+
library(scales)
10783

10884
set.seed(12345)
10985
Date <- seq(as.Date("2010/1/1"), as.Date("2014/1/1"), "week")
@@ -129,7 +105,7 @@ p <- ggplotly(p)
129105

130106
# Create a shareable link to your chart
131107
# Set up API credentials: https://plot.ly/r/getting-started
132-
chart_link = plotly_POST(p, filename="scalex/year")
108+
chart_link = api_create(p, filename="scalex/year")
133109
chart_link
134110
```
135111

0 commit comments

Comments
 (0)