Skip to content

Implement conversion for geom_hline #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions R/trace_generation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
)
Binary file added tests/testthat/test-ggplot-hline-ggplot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/testthat/test-ggplot-hline-plotly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions tests/testthat/test-ggplot-hline.R
Original file line number Diff line number Diff line change
@@ -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")
})
98 changes: 98 additions & 0 deletions tests/testthat/test-ggplot-hline.json
Original file line number Diff line number Diff line change
@@ -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)"
}
}
1 change: 1 addition & 0 deletions tests/testthat/test-ggplot-hline.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://plot.ly/~TestBot/561
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 123 additions & 0 deletions tests/testthat/test-ggplot-theme-marker-default.json
Original file line number Diff line number Diff line change
@@ -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)"
}
}
1 change: 1 addition & 0 deletions tests/testthat/test-ggplot-theme-marker-default.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://plot.ly/~TestBot/559