Skip to content
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

svglite output different than grDevices::svg, png #68

Closed
dekellum opened this issue Jul 28, 2016 · 2 comments
Closed

svglite output different than grDevices::svg, png #68

dekellum opened this issue Jul 28, 2016 · 2 comments

Comments

@dekellum
Copy link

Here is minimal reproducible script extracted from tidyverse/ggplot2#1686

Using ggplot2 2.1.0:

library(ggplot2)

p = ggplot(data.frame(x=1:10, y=1:10)) +
  geom_point(aes(x=x, y=y)) +
  geom_text( aes( x=x, y=y, label=y ), nudge_x=0.5 ) +
  theme( panel.grid.major.x = element_blank(), panel.grid.minor = element_blank() ) +
  theme( panel.grid.major.y = element_line(color = "#AAAAAA", linetype="dashed", size=0.33) )

ggsave( "svg_test.png", p, width=5.1, height=5.1 )
ggsave( "svg_test_svglite.svg", p, width=5.1, height=5.1 )
ggsave( "svg_test_gr.svg", p, width=5.1, height=5.1, device = grDevices::svg )

When comparing svg_test_svglite.svg to both svg_test_gr.svg and svg_test.png:

  1. svglite output doesn't honor panel.grid.major.y linetype="dashed"
  2. svglite output has viewBox="0 0 367.20 367.20", where as "grDevices::svg" output has width="367pt" height="367pt" and viewBox= "0 0 367 367"

I'm no expert on SVG, but (2) can effect the size of the SVG embedded in a web page if it is not otherwise set. Also if the web page does specify a fixed size, the svglite output might appear to have larger fonts than intended (since the entire rendering will be upscaled). Based on this the "grDevices::svg" output appears more comparable to the png and thus more correct.

@hadley
Copy link
Member

hadley commented Aug 15, 2016

I'm pretty sure the current sizing specification is correct, based on discussion with Paul Murrell.

Minimal reprex for dashing problem:

library(ggplot2)
p <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) +
  scale_x_continuous(NULL, breaks = NULL) + 
  scale_y_continuous(NULL, breaks = 1, labels = NULL) +
  geom_point() +
  theme_minimal() + 
  theme( 
    panel.grid.major.y = element_line(colour = "black", linetype = "dashed")
  )

p

@hadley
Copy link
Member

hadley commented Aug 15, 2016

Even more minimal reprex:

htmlSVG({
  plot.new()
  abline(h = 0.25, lty = "dashed", lwd = 0.5)
  abline(h = 0.5, lty = "dashed", lwd = 1)
  abline(h = 0.75, lty = "dashed", lwd = 5)
})

@hadley hadley closed this as completed in 01c7f0c Aug 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants