diff --git a/R/trace_generation.R b/R/trace_generation.R index fbba79a436..c3b878f2f7 100644 --- a/R/trace_generation.R +++ b/R/trace_generation.R @@ -294,6 +294,11 @@ toBasic <- list( g$params$xend <- max(g$prestats.data$globxmax) g }, + hline=function(g) { + g$params$xstart <- min(g$prestats.data$globxmin) + g$params$xend <- max(g$prestats.data$globxmax) + g + }, point=function(g) { if ("size" %in% names(g$data)) { g$params$sizemin <- min(g$prestats.data$globsizemin) @@ -510,5 +515,13 @@ geom2trace <- list( type="scatter", mode="lines", line=paramORdefault(params, aes2line, line.defaults)) + }, + hline=function(data, params) { + list(x=c(params$xstart, params$xend), + y=c(data$yintercept, data$yintercept), + name=params$name, + type="scatter", + mode="lines", + line=paramORdefault(params, aes2line, line.defaults)) } ) diff --git a/tests/testthat/test-ggplot-hline-ggplot2.png b/tests/testthat/test-ggplot-hline-ggplot2.png new file mode 100644 index 0000000000..30ddddb17f Binary files /dev/null and b/tests/testthat/test-ggplot-hline-ggplot2.png differ diff --git a/tests/testthat/test-ggplot-hline-plotly.png b/tests/testthat/test-ggplot-hline-plotly.png new file mode 100644 index 0000000000..6fee5bfcae Binary files /dev/null and b/tests/testthat/test-ggplot-hline-plotly.png differ diff --git a/tests/testthat/test-ggplot-hline.R b/tests/testthat/test-ggplot-hline.R new file mode 100644 index 0000000000..ff0f135868 --- /dev/null +++ b/tests/testthat/test-ggplot-hline.R @@ -0,0 +1,25 @@ +context("Hline") + +# Horizontal line + +test_that("Second trace be the hline", { + + x1 <- seq(from=0, to=3.5, by=0.5) + x2 <- x1 * 0.95 + df <- data.frame("x1"=x1, "x2"=x2) + + gg <- ggplot(df) + geom_point(aes(x=x1, y=x2)) + + geom_hline(yintercept=1.1, colour="green", size=3) + + L <- gg2list(gg) + + expect_equal(length(L), 3) + expect_true(L[[2]]$x[1] <= 0) + expect_true(L[[2]]$x[2] >= 3.5) + expect_identical(L[[2]]$mode, "lines") + expect_identical(L[[2]]$line$shape, "linear") + expect_equal(L[[2]]$line$width, 3) + expect_identical(L[[2]]$line$color, "rgb(0,255,0)") + + save_outputs(gg, "hline") +}) \ No newline at end of file diff --git a/tests/testthat/test-ggplot-hline.json b/tests/testthat/test-ggplot-hline.json new file mode 100644 index 0000000000..2a9fae84d2 --- /dev/null +++ b/tests/testthat/test-ggplot-hline.json @@ -0,0 +1,98 @@ +{ + "data": [ + { + "x": [ + 0, + 0.5, + 1, + 1.5, + 2, + 2.5, + 3, + 3.5 + ], + "y": [ + 0, + 0.475, + 0.95, + 1.4249999999999998, + 1.9, + 2.375, + 2.8499999999999996, + 3.3249999999999997 + ], + "mode": "markers", + "marker": { + "color": "rgb(0,0,0)", + "size": 10, + "symbol": "circle", + "opacity": 1, + "sizeref": 1, + "sizemode": "area" + }, + "xaxis": "x1", + "yaxis": "y1", + "showlegend": false, + "type": "scatter" + }, + { + "x": [ + -0.17500000000000002, + 3.675 + ], + "y": [ + 1.1, + 1.1 + ], + "mode": "lines", + "line": { + "color": "rgb(0,255,0)", + "width": 3, + "dash": "solid", + "shape": "linear" + }, + "xaxis": "x1", + "yaxis": "y1", + "showlegend": false, + "type": "scatter" + } + ], + "layout": { + "titlefont": { + "family": "" + }, + "showlegend": true, + "xaxis": { + "title": "x1", + "type": "linear", + "showgrid": true, + "showline": false, + "showticklabels": true, + "tickcolor": "rgb(127,127,127)", + "gridcolor": "rgb(255,255,255)" + }, + "yaxis": { + "title": "x2", + "type": "linear", + "showgrid": true, + "showline": false, + "showticklabels": true, + "tickcolor": "rgb(127,127,127)", + "gridcolor": "rgb(255,255,255)" + }, + "legend": { + "x": 100, + "y": 0.5, + "font": { + "family": "" + }, + "bgcolor": "rgb(255,255,255)", + "bordercolor": "transparent" + }, + "margin": { + "r": 10 + }, + "paper_bgcolor": "rgb(255,255,255)", + "plot_bgcolor": "rgb(229,229,229)" + } +} diff --git a/tests/testthat/test-ggplot-hline.url b/tests/testthat/test-ggplot-hline.url new file mode 100644 index 0000000000..0b682abec6 --- /dev/null +++ b/tests/testthat/test-ggplot-hline.url @@ -0,0 +1 @@ +https://plot.ly/~TestBot/561 diff --git a/tests/testthat/test-ggplot-theme-marker-default-ggplot2.png b/tests/testthat/test-ggplot-theme-marker-default-ggplot2.png new file mode 100644 index 0000000000..008a086dd8 Binary files /dev/null and b/tests/testthat/test-ggplot-theme-marker-default-ggplot2.png differ diff --git a/tests/testthat/test-ggplot-theme-marker-default-plotly.png b/tests/testthat/test-ggplot-theme-marker-default-plotly.png new file mode 100644 index 0000000000..9ad39ab89d Binary files /dev/null and b/tests/testthat/test-ggplot-theme-marker-default-plotly.png differ diff --git a/tests/testthat/test-ggplot-theme-marker-default.json b/tests/testthat/test-ggplot-theme-marker-default.json new file mode 100644 index 0000000000..b211be567d --- /dev/null +++ b/tests/testthat/test-ggplot-theme-marker-default.json @@ -0,0 +1,123 @@ +{ + "data": [ + { + "x": [ + 4.2 + ], + "y": [ + 0.38 + ], + "mode": "markers", + "name": "Paraguay", + "text": "size: 7", + "marker": { + "color": "rgb(248,118,109)", + "size": [ + 2.5 + ], + "symbol": "circle", + "line": { + "width": 0 + }, + "opacity": 1, + "sizeref": 1, + "sizemode": "area" + }, + "xaxis": "x1", + "yaxis": "y1", + "type": "scatter" + }, + { + "x": [ + 1.75 + ], + "y": [ + 1.67 + ], + "mode": "markers", + "name": "Peru", + "text": "size: 31", + "marker": { + "color": "rgb(0,186,56)", + "size": [ + 15.26595744680851 + ], + "symbol": "circle", + "line": { + "width": 0 + }, + "opacity": 1, + "sizeref": 1, + "sizemode": "area" + }, + "xaxis": "x1", + "yaxis": "y1", + "type": "scatter" + }, + { + "x": [ + 1.33 + ], + "y": [ + 0.43 + ], + "mode": "markers", + "name": "Philippines", + "text": "size: 101", + "marker": { + "color": "rgb(97,156,255)", + "size": [ + 52.5 + ], + "symbol": "circle", + "line": { + "width": 0 + }, + "opacity": 1, + "sizeref": 1, + "sizemode": "area" + }, + "xaxis": "x1", + "yaxis": "y1", + "type": "scatter" + } + ], + "layout": { + "titlefont": { + "family": "" + }, + "showlegend": true, + "xaxis": { + "title": "edu", + "type": "linear", + "showgrid": true, + "showline": false, + "showticklabels": true, + "tickcolor": "rgb(127,127,127)", + "gridcolor": "rgb(255,255,255)" + }, + "yaxis": { + "title": "illn", + "type": "linear", + "showgrid": true, + "showline": false, + "showticklabels": true, + "tickcolor": "rgb(127,127,127)", + "gridcolor": "rgb(255,255,255)" + }, + "legend": { + "x": 100, + "y": 0.5, + "font": { + "family": "" + }, + "bgcolor": "rgb(255,255,255)", + "bordercolor": "transparent" + }, + "margin": { + "r": 10 + }, + "paper_bgcolor": "rgb(255,255,255)", + "plot_bgcolor": "rgb(229,229,229)" + } +} diff --git a/tests/testthat/test-ggplot-theme-marker-default.url b/tests/testthat/test-ggplot-theme-marker-default.url new file mode 100644 index 0000000000..693e7d463b --- /dev/null +++ b/tests/testthat/test-ggplot-theme-marker-default.url @@ -0,0 +1 @@ +https://plot.ly/~TestBot/559