How do you save a high resolution image of a trajectory to disk?

57 views
Skip to first unread message

Ian Bowns

unread,
Aug 11, 2018, 10:08:53 AM8/11/18
to simmer-devel
Hi.

It seems that using printing devices such as png("file.png") doesn't print out a plot of a trajectory. Saving the plot from the Viewer pane results in a low-res image being saved.

So, how can I save a high resolution image of a trajectory plot? 

Thanks in anticipation,

Ian

Iñaki Úcar

unread,
Aug 11, 2018, 2:27:29 PM8/11/18
to simmer-devel
The png() function has a "res" argument (resolution, in ppi), which by
default is 72 ppi (too low). Try to increase it to 150 or 300 ppi.

Iñaki

>
> Thanks in anticipation,
>
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups "simmer-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simmer-devel...@googlegroups.com.
> To post to this group, send email to simmer...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/c7add029-1895-4cc8-b2fe-16401a4a2c4f%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Iñaki Úcar
http://www.enchufa2.es
@Enchufa2

Ian Bowns

unread,
Aug 11, 2018, 4:09:02 PM8/11/18
to simmer...@googlegroups.com
I don't get a file when I use png() is blank file on the plot(.traj). Other plots are fine. 

Iñaki Úcar

unread,
Aug 11, 2018, 4:41:35 PM8/11/18
to simmer-devel
El sáb., 11 ago. 2018 a las 22:09, Ian Bowns (<ianb...@gmail.com>) escribió:
>
> I don't get a file when I use png() is blank file on the plot(.traj). Other plots are fine.

Ahm, you are right, because it is not a plot, but an htmlwidget. Take
a look at here: https://github.com/ramnathv/htmlwidgets/issues/95

If you manage to save the SVG (I think I used DiagrammeRsvg or rsvg at
some point), then you can convert it to PNG with any resolution you
may need.

Iñaki

ianb...@gmail.com

unread,
Aug 11, 2018, 4:51:16 PM8/11/18
to simmer...@googlegroups.com
Thanks.

I'll take a look.

It is particularly important for me to get a reasonable resolution representation of the trajectory, as it is a care pathway for patients. A grainy image is no use when explaining this to the clinical team.

P.S. I'm still having problems getting a realistic simulation of a pathway when events may take a while (several hours), and teams include part-time staff. Will do a separate post on this.

Ian Bowns
E ianb...@gmail.com
M 07793 886943
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq32UcPBrnmCTxfxYRLOak1O9YJN7LKYq-5VZf8p%2BkUnJw%40mail.gmail.com.

ianb...@gmail.com

unread,
Aug 11, 2018, 4:59:55 PM8/11/18
to simmer...@googlegroups.com
My immediate reaction to the link is I can't understand most of what they're talking about.

Some of what I can, is simply incorrect. For example:

"Use the Export -> Save As Image menu within the RStudio Viewer (this will let the user export a PNG of whatever size they need)."

This is not true. The resolution options are limited and simply not good enough for a complex trajectory.

Not sure I have time for this. I retire very soon!

Ian Bowns
E ianb...@gmail.com
M 07793 886943

-----Original Message-----
From: simmer...@googlegroups.com <simmer...@googlegroups.com> On Behalf Of Iñaki Úcar
Sent: 11 August 2018 21:41
To: simmer-devel <simmer...@googlegroups.com>
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq32UcPBrnmCTxfxYRLOak1O9YJN7LKYq-5VZf8p%2BkUnJw%40mail.gmail.com.

Iñaki Úcar

unread,
Aug 11, 2018, 6:17:35 PM8/11/18
to simmer-devel
This works for me:

library(simmer.plot)
library(DiagrammeRsvg)
library(rsvg)

x <- trajectory() %>%
seize("res", 1) %>%
timeout(1) %>%
release("res", 1) %>%
rollback(3)

p <- plot(x)
svg <- charToRaw(export_svg(p))
rsvg_png(svg, "out.png", width=2000)
> To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/001d01d431b5%240b85b2a0%24229117e0%24%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

ianb...@gmail.com

unread,
Aug 12, 2018, 5:45:54 AM8/12/18
to simmer...@googlegroups.com
It also works for me. Thanks Iñaki.

Ian
To view this discussion on the web visit https://groups.google.com/d/msgid/simmer-devel/CALEXWq1RTTSiVy3Mgt0rUyptY%3DpZmnHprL7NR%3Dsr2-%2BVEm5ZmA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages