Reputation: 2609
I'm trying to use R to prototype a data visualization web application. My plan is to create a png file that will be inserted into the page for now. My problem is that I can't find a way to control the actual size of the graphs created by R. Here's my html file:
<!DOCTYPE html>
<html>
<head>...</head>
<body>
<div id="viz1">
<?php
exec('Rscript index.r');
echo ('<img src="temp.png" />');
unlink('temp2.png');
?>
</div>
</body>
</html>
This is my simple R script for creating a histogram:
png(
filename = 'temp2.png'
, width = 200
, height = 200
, units = 'px'
, res = NA
)
hist(rnorm(100), col = 'red')
dev.off()
The width and height specified by the png() function doesn't change the size of the graph.
Possible duplicates, but somewhat different: how can i change the size of a png file with R
Upvotes: 1
Views: 628
Reputation: 2609
As mathematical.coffee pointed out, I was actually asking the wrong question. The size of the png file is created. It is simply the size of the img element in the HTML that was causing my problem.
A quick hack fixed my problem:
<img src="temp2.png" style="width: 200px; height: 200px" />
Upvotes: 1