Skip to content

Commit ab4ca1c

Browse files
committed
Fix style (notably, RStudio indentation)
1 parent d142570 commit ab4ca1c

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

R/ggplotly.R

+19-19
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ gg2list <- function(p) {
110110
p$layers[[layer.i]]$data <- p$data
111111
}
112112
}
113-
113+
114114
# Test fill and color to see if they encode a quantitative
115115
# variable. This may be useful for several reasons: (1) it is
116116
# sometimes possible to plot several different colors in the same
@@ -190,7 +190,7 @@ gg2list <- function(p) {
190190
ggsizemin <- min(unlist(sizerange))
191191
ggsizemax <- max(unlist(sizerange))
192192
}
193-
193+
194194
layer.legends <- list()
195195
for(i in seq_along(built$plot$layers)){
196196
# This is the layer from the original ggplot object.
@@ -225,7 +225,7 @@ gg2list <- function(p) {
225225
L$prestats.data <-
226226
merge(prestats,
227227
gglayout[, c("PANEL", "plotly.row", "COL")])
228-
228+
229229
# Add global range info.
230230
for(xy in names(ranges.list)){
231231
range.vec <- ranges.list[[xy]]
@@ -356,7 +356,7 @@ gg2list <- function(p) {
356356
grid <- theme.pars$panel.grid
357357
grid.major <- theme.pars$panel.grid.major
358358
if ((!is.null(grid$linetype) || !is.null(grid.major$linetype)) &&
359-
c(grid$linetype, grid.major$linetype) %in% c(2, 3, "dashed", "dotted")) {
359+
c(grid$linetype, grid.major$linetype) %in% c(2, 3, "dashed", "dotted")) {
360360
ax.list$gridcolor <- ifelse(is.null(grid.major$colour),
361361
toRGB(grid$colour, 0.1),
362362
toRGB(grid.major$colour, 0.1))
@@ -392,7 +392,7 @@ gg2list <- function(p) {
392392
ax.list$tickangle <- -tick.text$angle
393393
}
394394
ax.list$tickfont <- theme2font(tick.text)
395-
395+
396396
## determine axis type first, since this information is used later
397397
## (trace.order.list is only used for type=category).
398398
title.text <- e(s("axis.title.%s"))
@@ -453,7 +453,7 @@ gg2list <- function(p) {
453453
}else{
454454
p$labels[[xy]]
455455
}
456-
456+
457457
ax.list$zeroline <- FALSE # ggplot2 plots do not show zero lines
458458
# Lines drawn around the plot border.
459459
ax.list$showline <- !is.blank("panel.border", TRUE)
@@ -603,16 +603,16 @@ gg2list <- function(p) {
603603
nann <- nann + 1
604604
}
605605
}
606-
# axes titles
607-
annotations[[nann]] <- make.label(xaxis.title,
608-
0.5,
609-
-outer.margin,
610-
yanchor="top")
611-
nann <- nann + 1
612-
annotations[[nann]] <- make.label(yaxis.title,
613-
-outer.margin,
614-
0.5,
615-
textangle=-90)
606+
# axes titles
607+
annotations[[nann]] <- make.label(xaxis.title,
608+
0.5,
609+
-outer.margin,
610+
yanchor="top")
611+
nann <- nann + 1
612+
annotations[[nann]] <- make.label(yaxis.title,
613+
-outer.margin,
614+
0.5,
615+
textangle=-90)
616616
layout$annotations <- annotations
617617
}
618618

@@ -631,7 +631,7 @@ gg2list <- function(p) {
631631
layout$legend <- list(bordercolor="transparent",
632632
x=1.05, y=1/2,
633633
xanchor="center", yanchor="top")
634-
634+
635635
## Legend hiding when guides(fill="none").
636636
legends.present <- unique(unlist(layer.legends))
637637
is.false <- function(x){
@@ -653,7 +653,7 @@ gg2list <- function(p) {
653653
if(theme.pars$legend.position=="none"){
654654
layout$showlegend <- FALSE
655655
}
656-
656+
657657
# Only show a legend title if there is at least 1 trace with
658658
# showlegend=TRUE.
659659
trace.showlegend <- sapply(trace.list, "[[", "showlegend")
@@ -908,7 +908,7 @@ gg2list <- function(p) {
908908
}
909909

910910
fig <- list(data=flipped.traces, layout=flipped.layout)
911-
911+
912912
fig
913913

914914
}

R/trace_generation.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ layer2traces <- function(l, d, misc) {
1313
g <- list(geom=l$geom$objname,
1414
data=not.na(d),
1515
prestats.data=not.na(l$prestats.data))
16-
16+
1717
# needed for when group, etc. is an expression.
1818
g$aes <- sapply(l$mapping, function(k) as.character(as.expression(k)))
1919
# Partial conversion for geom_violin (Plotly does not offer KDE yet)
@@ -46,7 +46,7 @@ layer2traces <- function(l, d, misc) {
4646
g$geom <- "bar"
4747
bargap <- 0
4848
}
49-
49+
5050
# For non-numeric data on the axes, we should take the values from
5151
# the original data.
5252
for (axis.name in c("x", "y")) {
@@ -136,7 +136,7 @@ layer2traces <- function(l, d, misc) {
136136

137137
# symbol=circle,square,diamond,cross,x,
138138
# triangle-up,triangle-down,triangle-left,triangle-right
139-
139+
140140
# First convert to a "basic" geom, e.g. segments become lines.
141141
convert <- toBasic[[g$geom]]
142142
basic <- if(is.null(convert)){
@@ -247,7 +247,7 @@ layer2traces <- function(l, d, misc) {
247247
if (is.null(tr$name) || tr$name %in% names.in.legend)
248248
tr$showlegend <- FALSE
249249
names.in.legend <- c(names.in.legend, tr$name)
250-
250+
251251
# special handling for bars
252252
if (g$geom == "bar") {
253253
tr$bargap <- if (exists("bargap")) bargap else "default"
@@ -270,7 +270,7 @@ layer2traces <- function(l, d, misc) {
270270
0
271271
}
272272
})
273-
273+
274274
ord <- order(sort.val)
275275
no.sort <- traces[ord]
276276
for(tr.i in seq_along(no.sort)){

tests/testthat/test-cookbook-axes.R

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ context("cookbook axes")
33
bp <- ggplot(PlantGrowth, aes(x=group, y=weight)) +
44
geom_boxplot()
55

6-
expect_traces <- function(gg, n.traces, name){
6+
expect_traces <- function(gg, n.traces, name) {
77
stopifnot(is.ggplot(gg))
88
stopifnot(is.numeric(n.traces))
99
save_outputs(gg, paste0("cookbook-axes-", name))
@@ -17,13 +17,13 @@ expect_traces <- function(gg, n.traces, name){
1717
list(traces=has.data, layout=L$layout)
1818
}
1919

20-
get_legend <- function(L){
21-
if(!isTRUE(L$kwargs$layout$showlegend)){
20+
get_legend <- function(L) {
21+
if (!isTRUE(L$kwargs$layout$showlegend)) {
2222
return(data.frame())
2323
}
2424
legend.list <- list()
25-
for(tr in L$traces){
26-
if(is.character(tr$name)){
25+
for (tr in L$traces) {
26+
if (is.character(tr$name)) {
2727
legend.list[[tr$name]] <-
2828
data.frame(name=tr$name, showlegend=tr$showlegend)
2929
}
@@ -32,12 +32,12 @@ get_legend <- function(L){
3232
subset(legend.df, showlegend)
3333
}
3434

35-
leg <- function(...){
35+
leg <- function(...) {
3636
name <- c(...)
3737
data.frame(name)
3838
}
3939

40-
expect_legend <- function(L, expected){
40+
expect_legend <- function(L, expected) {
4141
stopifnot(is.data.frame(expected))
4242
shown <- get_legend(L)
4343
expect_identical(shown$name, expected$name)
@@ -59,7 +59,7 @@ test_that("factor levels determine tick order", {
5959
c("trt2", "trt1", "ctrl"))
6060
expect_legend(info, leg())
6161
})
62-
62+
6363
## These two do the same thing; all data points outside the graphing
6464
## range are dropped, resulting in a misleading box plot.
6565
bp.ylim.hide <- bp + ylim(5, 7.5)
@@ -74,7 +74,7 @@ test_that("scale_y(limits) hides points", {
7474
expect_legend(info, leg())
7575
expect_equal(info$layout$yaxis$range, c(5, 7.5))
7676
})
77-
77+
7878
bp.coord <- bp + coord_cartesian(ylim=c(5, 7.5))
7979
test_that("Using coord_cartesian zooms into the area", {
8080
info <- expect_traces(bp.coord, 3, "coord-ylim")
@@ -93,11 +93,12 @@ sp <- ggplot(dat, aes(xval, yval)) + geom_point()
9393

9494
test_that("A scatterplot with regular (linear) axis scaling", {
9595
info <- expect_traces(sp, 1, "linear-axes")
96-
## TODO: why does this test take so long?
96+
# TODO: why does this test take so long?
9797
expect_legend(info, leg())
9898
})
9999

100-
library(scales) # Need the scales package
100+
library(scales)
101+
# TODO: Add package "scales" to the list of dependencies?
101102
sp.log2.scale <- sp + scale_y_continuous(trans=log2_trans())
102103

103104
test_that("log2 scaling of the y axis (with visually-equal spacing)", {
@@ -214,12 +215,12 @@ test_that("In this particular case, x scale has no effect", {
214215

215216
# Self-defined formatting function for times.
216217
timeHMS_formatter <- function(x) {
217-
h <- floor(x/60)
218-
m <- floor(x %% 60)
219-
s <- round(60*(x %% 1)) # Round to nearest second
220-
lab <- sprintf("%02d:%02d:%02d", h, m, s) # Format the strings as HH:MM:SS
221-
lab <- gsub("^00:", "", lab) # Remove leading 00: if present
222-
lab <- gsub("^0", "", lab) # Remove leading 0 if present
218+
h <- floor(x/60)
219+
m <- floor(x %% 60)
220+
s <- round(60*(x %% 1)) # Round to nearest second
221+
lab <- sprintf("%02d:%02d:%02d", h, m, s) # Format the strings as HH:MM:SS
222+
lab <- gsub("^00:", "", lab) # Remove leading 00: if present
223+
lab <- gsub("^0", "", lab) # Remove leading 0 if present
223224
}
224225

225226
custom.formatter <- bp + scale_y_continuous(label=timeHMS_formatter)
@@ -263,4 +264,3 @@ test_that("Hide all the vertical gridlines", {
263264
info <- expect_traces(blank.y, 3, "blank-y")
264265
expect_legend(info, leg())
265266
})
266-

tests/testthat/test-cookbook-lines.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,18 @@ df.vlines <- data.frame(cond = levels(df$cond), xval = c(10,11.5))
235235

236236
spf.vline <-
237237
spf +
238-
geom_hline(aes(yintercept = 10)) +
239-
geom_vline(aes(xintercept = xval),
240-
data = df.vlines,
241-
colour = "#990000", linetype = "dashed")
238+
geom_hline(aes(yintercept = 10)) +
239+
geom_vline(aes(xintercept = xval),
240+
data = df.vlines,
241+
colour = "#990000", linetype = "dashed")
242242
test_that("geom_vline -> 2 more traces", {
243243
info <- expect_traces_shapes(spf.vline, 6, 0, "scatter-facet-hline-vline")
244244
})
245245

246246
spf.line.stat <-
247247
spf +
248-
geom_hline(aes(yintercept=10)) +
249-
geom_line(stat="vline", xintercept="mean")
248+
geom_hline(aes(yintercept=10)) +
249+
geom_line(stat="vline", xintercept="mean")
250250
test_that("geom_line -> 2 more traces", {
251251
info <-
252252
expect_traces_shapes(spf.line.stat, 6, 0,

0 commit comments

Comments
 (0)