8000 use 'fig' only for plotly and still 'p' for ggplot · plotly/plotly.r-docs@cca31f6 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cca31f6

Browse files
author
mahdis-z
committed
use 'fig' only for plotly and still 'p' for ggplot
1 parent 6f1ef9f commit cca31f6

File tree

76 files changed

+488
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+488
-490
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ require(lubridate)
3434
MySample$date <- as.Date(MySample$x, "%m-%d-%y")
3535
MySample$year <- year(MySample$date)
3636
37-
fig <- ggplot(MySample, aes(date, y, fill = year)) +
37+
p <- ggplot(MySample, aes(date, y, fill = year)) +
3838
geom_bar(stat="identity") +
3939
facet_grid(. ~ year, scales = "free") +
4040
scale_x_date(labels = date_format("%b/%y")) +
4141
scale_fill_gradient(breaks=unique(MySample$year))
4242
43-
fig <- ggplotly(fig)
43+
fig <- ggplotly(p)
4444
4545
fig
4646
```
@@ -65,14 +65,14 @@ df$MonthDay <- format(df$Date, "%d-%b")
6565
6666
df$CommonDate <- as.Date(paste0("2000-",format(df$Date, "%j")), "%Y-%j")
6767
68-
fig <- ggplot(data = df,
68+
p <- ggplot(data = df,
6969
mapping = aes(x = CommonDate, y = Y, shape = Year, colour = Year)) +
7070
geom_point() +
7171
geom_line() +
7272
facet_grid(facets = Year ~ .) +
7373
scale_x_date(labels = function(x) format(x, "%d-%b"))
7474
75-
fig <- ggplotly(fig)
75+
fig <- ggplotly(p)
7676
7777
fig
7878
```

ggplot2/2011-11-29-scale-y.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ knitr::opts_chunk$set(message = FALSE, warning=FALSE)
2121
```{r}
2222
library(plotly)
2323
24-
fig <- ggplot(diamonds, aes(color, log10(price))) +
24+
p <- ggplot(diamonds, aes(color, log10(price))) +
2525
geom_boxplot() +
2626
scale_y_continuous("Price, log10-scaling")
2727
28-
fig <- ggplotly(fig)
28+
fig <- ggplotly(p)
2929
3030
fig
3131
```

ggplot2/2016-11-29-aes.Rmd

Lines changed: 8 additions & 8 deletions
< 10000 td data-grid-cell-id="diff-8be54ea60d925cb564f57f6aa8f09db700e675a544f7d8ffaac66d1c41d9092c-57-57-1" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">57
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ ds <- data.frame(x = 1:10,
2525
group = LETTERS[1:2])
2626
2727
# Use the fill aesthetic to specify the fill color for the bars
28-
fig <- ggplot(ds, aes(x, y)) +
28+
p <- ggplot(ds, aes(x, y)) +
2929
geom_bar(aes(fill = group), stat = "identity") +
3030
ggtitle("Filled bar chart")
3131
32-
fig <- ggplotly(fig)
32+
fig <- ggplotly(p)
3333
3434
fig
3535
```
@@ -53,11 +53,11 @@ group <- c(rep("A", length(x1)),
5353
ds <- data.frame(x, y, group)
5454
5555
# Use the group aesthetic to ensure lines are drawn separately for each group
56-
fig <- ggplot(ds, aes(x, y)) +
56+
p <- ggplot(ds, aes(x, y)) +
57
geom_line(aes(group = group, color = group), size = 2) +
5858
ggtitle("Group specific line chart")
5959
60-
fig <- ggplotly(fig)
60+
fig <- ggplotly(p)
6161
6262
fig
6363
```
@@ -71,12 +71,12 @@ ds <- data.frame(x = rnorm(10),
7171
y = rnorm(10),
7272
group = LETTERS[1:2])
7373
74-
fig <- ggplot(ds, aes(x, y)) +
74+
p <- ggplot(ds, aes(x, y)) +
7575
geom_point(aes(color = group), size = 7) +
7676
geom_text(aes(label = group), size = 4) +
7777
ggtitle("Annotation with labels")
7878
79-
fig <- ggplotly(fig)
79+
fig <- ggplotly(p)
8080
8181
fig
8282
```
@@ -91,12 +91,12 @@ ds <- data.frame(x = letters[1:5],
9191
group = LETTERS[1:4])
9292
9393
# Use aes shape to map individual points and or different groups to different shapes
94-
fig <- ggplot(ds, aes(x, y)) +
94+
p <- ggplot(ds, aes(x, y)) +
9595
geom_point(aes(color = group, shape = group), size = 5) +
9696
geom_line(aes(group = group, linetype = group)) +
9797
ggtitle("Groupwise shapes and line types")
9898
99-
fig <- ggplotly(fig)
99+
fig <- ggplotly(p)
100100
101101
fig
102102
```

ggplot2/2016-11-29-axis-text.Rmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ set.seed(123)
2323
2424
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
2525
26-
fig <- ggplot(d 6D4E f, aes(carat, price, color = color, alpha = cut)) +
26+
p <- ggplot(df, aes(carat, price, color = color, alpha = cut)) +
2727
geom_point() +
2828
theme(axis.text.x = element_text(colour = "#ff6666", size = 20),
2929
axis.text.y = element_text(colour = "#668cff", size = 20))
3030
31-
fig <- ggplotly(fig)
31+
fig <- ggplotly(p)
3232
3333
fig
3434
```
@@ -41,11 +41,11 @@ set.seed(123)
4141
4242
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
4343
44-
fig <- ggplot(df, aes(carat, price, color = cut)) +
44+
p <- ggplot(df, aes(carat, price, color = cut)) +
4545
geom_point() +
4646
theme(axis.text = element_blank())
4747
48-
fig <- ggplotly(fig)
48+
fig <- ggplotly(p)
4949
5050
fig
5151
```
@@ -60,12 +60,12 @@ lab <- paste("Vertical Label", c(1, 2, 3, 4, 5))
6060
ds <- data.frame(x = sample(lab, size = 1000, replace = T),
6161
y = sample(LETTERS[1:5], size = 1000, replace = T))
6262
63-
fig <- ggplot(ds, aes(x = x, fill = y)) +
63+
p <- ggplot(ds, aes(x = x, fill = y)) +
6464
geom_bar() +
6565
theme(axis.text.x = element_text(angle = 90)) +
6666
ggtitle("Vertical Axis Labels")
6767
68-
fig <- ggplotly(fig)
68+
fig <- ggplotly(p)
6969
7070
fig
7171
```
@@ -80,12 +80,12 @@ lab <- paste("Angle Label", c(1, 2, 3, 4, 5))
8080
ds <- data.frame(x = sample(lab, size = 1000, replace = T),
8181
y = sample(LETTERS[1:5], size = 1000, replace = T))
8282
83-
fig <- ggplot(ds, aes(x = x, fill = y)) +
83+
p <- ggplot(ds, aes(x = x, fill = y)) +
8484
geom_bar() +
8585
theme(axis.text.x = element_text(angle = 45)) +
8686
ggtitle("Angle Axis Labels")
8787
88-
fig <- ggplotly(fig)
88+
fig <- ggplotly(p)
8989
9090
fig
9191
```

ggplot2/2016-11-29-axis-ticks.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ set.seed(123)
2323
2424
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
2525
26-
fig <- ggplot(df, aes(carat, price)) +
26+
p <- ggplot(df, aes(carat, price)) +
2727
geom_point() +
2828
theme(axis.ticks = element_line(size = 10))
2929
30-
fig <- ggplotly(fig)
30+
fig <- ggplotly(p)
3131
3232
fig
3333
```

ggplot2/2016-11-29-axis-title.Rmd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ set.seed(123)
2424
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
2525
2626
# To set x-axis and y-axis labels use labs()
27-
fig <- ggplot(df, aes(carat, price)) +
27+
p <- ggplot(df, aes(carat, price)) +
2828
geom_point() +
2929
labs(title = "Diamonds", x = "x-axis -> Carat", y = "y-axis -> Price")
3030
31-
fig <- ggplotly(fig)
31+
fig <- ggplotly(p)
3232
3333
# Alternatively use
34-
fig <- ggplot(df, aes(carat, price)) +
34+
p <- ggplot(df, aes(carat, price)) +
3535
geom_point() +
3636
ggtitle("Diamonds") +
3737
xlab("x-axis -> Carat") +
3838
ylab("y-axis -> Price")
3939
40-
fig <- ggplotly(fig)
40+
fig <- ggplotly(p)
4141
4242
fig
4343
```
@@ -50,14 +50,14 @@ set.seed(123)
5050
5151
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
5252
53-
fig <- ggplot(df, aes(carat, price)) +
53+
p <- ggplot(df, aes(carat, price)) +
5454
geom_point() +
5555
labs(title = "Diamonds", x = "x-axis -> Carat", y = "y-axis -> Price") +
5656
theme(plot.title = element_text(size = 50),
5757
axis.title.x = element_text(size = 20),
5858
axis.title.y = element_text(size = 20))
5959
60-
fig <- ggplotly(fig)
60+
fig <- ggplotly(p)
6161
6262
fig
6363
```
@@ -70,14 +70,14 @@ set.seed(123)
7070
7171
df <- diamonds[sample(1:nrow(diamonds), size = 1000),]
7272
73-
fig <- ggplot(df, aes(carat, price)) +
73+
p <- ggplot(df, aes(carat, price)) +
7474
geom_point() +
7575
labs(title = "Diamonds", x = "x-axis -> Carat", y = "y-axis -> Price") +
7676
theme(plot.title = element_text(size = 50, colour = "#668cff"),
7777
axis.title.x = element_text(size = 20, colour = "#6699ff"),
7878
axis.title.y = element_text(size = 20, colour = "#ff8080"))
7979
80-
fig <- ggplotly(fig)
80+
fig <- ggplotly(p)
8181
8282
fig
8383
```

ggplot2/2016-11-29-facet-grid.Rmd

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ knitr::opts_chunk$set(message = FALSE, warning=FALSE)
2222
library(reshape2)
2323
library(plotly)
2424
25-
fig <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
25+
p <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
2626
2727
# Divide by levels of "sex", in the vertical direction
28-
fig <- fig + facet_grid(sex ~ .)
28+
p <- p + facet_grid(sex ~ .)
2929
30-
fig <- ggplotly(fig)
30+
fig <- ggplotly(p)
3131
3232
fig
3333
```
@@ -38,12 +38,12 @@ fig
3838
library(reshape2)
3939
library(plotly)
4040
41-
fig <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
41+
p <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1)
4242
4343
# Divide by levels of "sex", in the horizontal direction
44-
fig <- fig + facet_grid(. ~ sex)
44+
p <- p + facet_grid(. ~ sex)
4545
46-
fig <- ggplotly(fig)
46+
fig <- ggplotly(p)
4747
4848
fig
4949
```
@@ -54,12 +54,12 @@ fig
5454
library(reshape2)
5555
library(plotly)
5656
57-
fig <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
57+
p <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
5858
5959
# Histogram of total_bill, divided by sex and smoker
60-
fig <- fig + facet_grid(sex ~ smoker)
60+
p <- p + facet_grid(sex ~ smoker)
6161
62-
fig <- ggplotly(fig)
62+
fig <- ggplotly(p)
6363
6464
fig
6565
```
@@ -70,12 +70,12 @@ fig
7070
library(reshape2)
7171
library(plotly)
7272
73-
fig <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
73+
p <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
7474
7575
# Same as above, with scales="free_y"
76-
fig <- fig + facet_grid(sex ~ smoker, scales="free_y")
76+
p <- p + facet_grid(sex ~ smoker, scales="free_y")
7777
78-
fig <- ggplotly(fig)
78+
fig <- ggplotly(p)
7979
8080
fig
8181
```
@@ -86,12 +86,12 @@ fig
8686
library(reshape2)
8787
library(plotly)
8888
89-
fig <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
89+
p <- ggplot(tips, aes(x=total_bill)) + geom_histogram(binwidth=2,colour="white")
9090
9191
# With panels that have the same scaling, but different range (and therefore different physical sizes)
92-
fig <- fig + facet_grid(sex ~ smoker, scales="free", space="free")
92+
p <- p + facet_grid(sex ~ smoker, scales="free", space="free")
9393
94-
fig <- ggplotly(fig)
94+
fig <- ggplotly(p)
9595
9696
fig
9797
```
@@ -108,7 +108,7 @@ mymelt <- structure(list(mydate = structure(c(15340, 15340, 15340, 15340, 15340,
108108
myvals <- mymelt[mymelt$mydate == mymelt$mydate[nrow(mymelt)],] ## last date in mymelt should always be same as plotenddate as we subset earlier
109109
mymelt <- within(mymelt, variable <- factor(variable, as.character(myvals[order(myvals$value, decreasing = T),]$variable), ordered = TRUE))
110110
111-
fig <- ggplot(mymelt, aes(x = mydate, y = value)) +
111+
p <- ggplot(mymelt, aes(x = mydate, y = value)) +
112112
geom_line(lwd=0.3) +
113113
facet_grid(. ~ variable) +
114114
theme(axis.text.x = element_text(size = 5, angle = 90),
@@ -117,7 +117,7 @@ fig <- ggplot(mymelt, aes(x = mydate, y = value)) +
117117
axis.ticks = element_blank(),
118118
panel.grid.minor = element_blank())
119119
120-
fig <- ggplotly(fig)
120+
fig <- ggplotly(p)
121121
122122
fig
123123
```
@@ -137,11 +137,11 @@ value <- c(sample(1:10, size=365, replace=T),sample(1:3, size=365, replace=T),
137137
sample(1:100, size=365, replace=T))
138138
dat<-data.frame(date,location,product,value)
139139
140-
fig <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
140+
p <- ggplot(dat, aes(x=date, y=value, color=location, group=location)) +
141141
geom_line()+
142142
facet_grid(product ~ ., scale = "free_y")
143143
144-
fig <- ggplotly(fig)
144+
fig <- ggplotly(p)
145145
146146
fig
147147
```

0 commit comments

Comments
 (0)
0