Hi,
I have been trying to output my graphs to a file (jpeg, pdf, ps, it
doesnt matter) but i cant seem to be able to get it to output. I tried a
few things but none of them worked and am lost as what to do now. I am
using the scatter3d function, and it prints out the graphs on tot he
screen without any problems, but when it comes to writing them to a file
i cant make it work. Is there any other way of producing 3dimensional
graphs (they dont have to be rotatable/interactive after the print out)?
The code is fairly simple and is listed down :
#libraries
library(RMySQL)
library(rgl)
library(scatterplot3d)
library(Rcmdr)
##############################################################################
#database connection
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
#distinct sessions
rsSessionsU01 <- dbSendQuery(mycon, "select distinct sessionID from
actiontimes where userID = 'ID01'")
sessionU01 <-fetch(rsSessionsU01)
sessionU01[2,]
#user01 data
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
rsUser01 <- dbSendQuery(mycon, "select
a.userID,a.sessionID,a.actionTaken,a.timelineMSEC,a.durationMSEC,b.X,b.Y,b.Rel__dist_,b.Total_dist_
from `actiontimes` as a , `ulogdata` as b where a.originalRECNO =
b.RECNO and a.userID='ID01'")
user01 <- fetch(rsUser01, n= -1)
user01[1,1]
#plot loop
for (i in 1:10){
userSubset<-subset(user01,sessionID ==
sessionU01[i,],select=c(timelineMSEC,X,Y))
userSubset
x<-as.numeric(userSubset$X)
y<-as.numeric(userSubset$Y)
scatter3d(x,y,userSubset$timeline,xlim = c(0,1280), ylim =
c(0,1024),
zlim=c(0,1800000),type="h",main=sessionU01[i,],sub=sessionU01[i,])
tmp6=rep(".ps")
tmp7=paste(sessionU01[i,],tmp6,sep="")
tmp7
rgl.postscript(tmp7,"ps",drawText=FALSE)
#pdf(file=tmp7)
#dev.print(file=tmp7, device=pdf, width=600)
#dev.off(2)
}
Print plot to pdf, jpg or any other format when using scatter3d error
6 messages · David Winsemius, Uwe Ligges, Jurica Seva +1 more
On Jan 3, 2011, at 8:17 PM, Jurica Seva wrote:
Hi,
I have been trying to output my graphs to a file (jpeg, pdf, ps, it
doesnt matter) but i cant seem to be able to get it to output. I
tried a few things but none of them worked and am lost as what to do
now. I am using the scatter3d function, and it prints out the graphs
on tot he screen without any problems, but when it comes to writing
them to a file i cant make it work. Is there any other way of
producing 3dimensional graphs (they dont have to be rotatable/
interactive after the print out)?
The code is fairly simple and is listed down :
#libraries
library(RMySQL)
library(rgl)
library(scatterplot3d)
library(Rcmdr)
##############################################################################
#database connection
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
#distinct sessions
rsSessionsU01 <- dbSendQuery(mycon, "select distinct sessionID from
actiontimes where userID = 'ID01'")
sessionU01 <-fetch(rsSessionsU01)
sessionU01[2,]
#user01 data
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
rsUser01 <- dbSendQuery(mycon, "select
a
.userID
,a
.sessionID
,a
.actionTaken
,a.timelineMSEC,a.durationMSEC,b.X,b.Y,b.Rel__dist_,b.Total_dist_
from `actiontimes` as a , `ulogdata` as b where a.originalRECNO =
b.RECNO and a.userID='ID01'")
user01 <- fetch(rsUser01, n= -1)
user01[1,1]
#plot loop
for (i in 1:10){
userSubset<-subset(user01,sessionID ==
sessionU01[i,],select=c(timelineMSEC,X,Y))
userSubset
x<-as.numeric(userSubset$X)
y<-as.numeric(userSubset$Y)
scatter3d(
#??? I thought the function was scatterplot3d()
x,y,userSubset$timeline,xlim = c(0,1280), ylim = c(0,1024),
zlim=c(0,1800000),type="h",main=sessionU01[i,],sub=sessionU01[i,])
tmp6=rep(".ps")
Why name it ".ps" when you are using pdf.dev()?
tmp7=paste(sessionU01[i,],tmp6,sep="") tmp7 rgl.postscript(tmp7,"ps",drawText=FALSE)
When you want to get output to the file device, you need to "surround" the plotting commands. the pdf call goes at the beginning of the loop and the dev.odd at the end. It seems dangerous to specify the number to dev.off since there might be no or more than one device already open. If you just use dev.off() you will close the last device that was opened,'
#pdf(file=tmp7) # Move before the scatterplot3d call
#dev.print(file=tmp7, device=pdf, width=600)
# you should also make sure you created a valid file string. We cannot check since you have not offered a reproducible example.
#dev.off(2) }
David Winsemius, MD West Hartford, CT
On 04.01.2011 08:37, David Winsemius wrote:
On Jan 3, 2011, at 8:17 PM, Jurica Seva wrote:
Hi,
I have been trying to output my graphs to a file (jpeg, pdf, ps, it
doesnt matter) but i cant seem to be able to get it to output. I tried
a few things but none of them worked and am lost as what to do now. I
am using the scatter3d function, and it prints out the graphs on tot
he screen without any problems, but when it comes to writing them to a
file i cant make it work. Is there any other way of producing
3dimensional graphs (they dont have to be rotatable/interactive after
the print out)?
The code is fairly simple and is listed down :
#libraries
library(RMySQL)
library(rgl)
library(scatterplot3d)
library(Rcmdr)
##############################################################################
#database connection
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
#distinct sessions
rsSessionsU01 <- dbSendQuery(mycon, "select distinct sessionID from
actiontimes where userID = 'ID01'")
sessionU01 <-fetch(rsSessionsU01)
sessionU01[2,]
#user01 data
mycon <- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
rsUser01 <- dbSendQuery(mycon, "select
a.userID,a.sessionID,a.actionTaken,a.timelineMSEC,a.durationMSEC,b.X,b.Y,b.Rel__dist_,b.Total_dist_
from `actiontimes` as a , `ulogdata` as b where a.originalRECNO =
b.RECNO and a.userID='ID01'")
user01 <- fetch(rsUser01, n= -1)
user01[1,1]
#plot loop
for (i in 1:10){
userSubset<-subset(user01,sessionID ==
sessionU01[i,],select=c(timelineMSEC,X,Y))
userSubset
x<-as.numeric(userSubset$X)
y<-as.numeric(userSubset$Y)
scatter3d(
#??? I thought the function was scatterplot3d()
scatter3d() is provided by Rcmdr and an interface to the rgl package.
x,y,userSubset$timeline,xlim = c(0,1280), ylim = c(0,1024),
zlim=c(0,1800000),type="h",main=sessionU01[i,],sub=sessionU01[i,])
tmp6=rep(".ps")
Why name it ".ps" when you are using pdf.dev()?
Actually he is not using it (at least it is in comments).
tmp7=paste(sessionU01[i,],tmp6,sep="") tmp7 rgl.postscript(tmp7,"ps",drawText=FALSE)
That should be correct code, according to the rgl documentation.
When you want to get output to the file device, you need to "surround" the plotting commands. the pdf call goes at the beginning of the loop and the dev.odd at the end. It seems dangerous to specify the number to dev.off since there might be no or more than one device already open. If you just use dev.off() you will close the last device that was opened,'
Using R standard devices will not work for rgl graphics. Best wishes, Uwe
#pdf(file=tmp7) # Move before the scatterplot3d call
#dev.print(file=tmp7, device=pdf, width=600)
# you should also make sure you created a valid file string. We cannot check since you have not offered a reproducible example.
#dev.off(2) }
David Winsemius, MD West Hartford, CT
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On 03/01/2011 8:17 PM, Jurica Seva wrote:
Hi, I have been trying to output my graphs to a file (jpeg, pdf, ps, it doesnt matter) but i cant seem to be able to get it to output.
As Uwe said, you are using rgl graphics, not base graphics. So none of the standard devices work, you need to use the tools built into rgl. Attach that package, and then read ?rgl.postscript (for graphics in various vector formats, not just Postscript) and ?rgl.snapshot (for bitmapped graphics). Some notes: - For a while rgl.snapshot wasn't working in the Windows builds with R 2.12.1; that is now fixed, so you should update rgl before getting frustrated. - rgl.snapshot just takes a copy of the graphics buffer that is showing on screen, so it is limited to the size you can display - rgl.postscript does a better job for the parts of an image that it can handle, but it is not a perfect OpenGL emulator, so it doesn't always include all components of a graph properly. Duncan Murdoch
I tried a
few things but none of them worked and am lost as what to do now. I am
using the scatter3d function, and it prints out the graphs on tot he
screen without any problems, but when it comes to writing them to a file
i cant make it work. Is there any other way of producing 3dimensional
graphs (they dont have to be rotatable/interactive after the print out)?
The code is fairly simple and is listed down :
#libraries
library(RMySQL)
library(rgl)
library(scatterplot3d)
library(Rcmdr)
##############################################################################
#database connection
mycon<- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
#distinct sessions
rsSessionsU01<- dbSendQuery(mycon, "select distinct sessionID from
actiontimes where userID = 'ID01'")
sessionU01<-fetch(rsSessionsU01)
sessionU01[2,]
#user01 data
mycon<- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
rsUser01<- dbSendQuery(mycon, "select
a.userID,a.sessionID,a.actionTaken,a.timelineMSEC,a.durationMSEC,b.X,b.Y,b.Rel__dist_,b.Total_dist_
from `actiontimes` as a , `ulogdata` as b where a.originalRECNO =
b.RECNO and a.userID='ID01'")
user01<- fetch(rsUser01, n= -1)
user01[1,1]
#plot loop
for (i in 1:10){
userSubset<-subset(user01,sessionID ==
sessionU01[i,],select=c(timelineMSEC,X,Y))
userSubset
x<-as.numeric(userSubset$X)
y<-as.numeric(userSubset$Y)
scatter3d(x,y,userSubset$timeline,xlim = c(0,1280), ylim =
c(0,1024),
zlim=c(0,1800000),type="h",main=sessionU01[i,],sub=sessionU01[i,])
tmp6=rep(".ps")
tmp7=paste(sessionU01[i,],tmp6,sep="")
tmp7
rgl.postscript(tmp7,"ps",drawText=FALSE)
#pdf(file=tmp7)
#dev.print(file=tmp7, device=pdf, width=600)
#dev.off(2)
}
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110104/db7ec9aa/attachment.pl>
On 11-01-04 5:36 PM, Jurica Seva wrote:
Thank you, Duncan, it works now with rgl.snapshot (i did have to upgrade to 2.12.1). Is there any way to manipulate the size of the created image? The created plots are a bit small (256*256)
Sure, they're the size of the window: it's just a snapshot. Just make it bigger (by mouse, or using par3d(windowRect= ...)) before taking the snapshot. Duncan Murdoch
Thank you for your help once again :)
Best,
Jurica
On Tue, Jan 4, 2011 at 8:31 AM, Duncan Murdoch <murdoch.duncan at gmail.com
<mailto:murdoch.duncan at gmail.com>> wrote:
On 03/01/2011 8:17 PM, Jurica Seva wrote:
Hi,
I have been trying to output my graphs to a file (jpeg, pdf, ps, it
doesnt matter) but i cant seem to be able to get it to output.
As Uwe said, you are using rgl graphics, not base graphics. So none
of the standard devices work, you need to use the tools built into
rgl. Attach that package, and then read ?rgl.postscript (for
graphics in various vector formats, not just Postscript) and
?rgl.snapshot (for bitmapped graphics).
Some notes:
- For a while rgl.snapshot wasn't working in the Windows builds
with R 2.12.1; that is now fixed, so you should update rgl before
getting frustrated.
- rgl.snapshot just takes a copy of the graphics buffer that is
showing on screen, so it is limited to the size you can display
- rgl.postscript does a better job for the parts of an image that
it can handle, but it is not a perfect OpenGL emulator, so it
doesn't always include all components of a graph properly.
Duncan Murdoch
I tried a
few things but none of them worked and am lost as what to do
now. I am
using the scatter3d function, and it prints out the graphs on tot he
screen without any problems, but when it comes to writing them
to a file
i cant make it work. Is there any other way of producing
3dimensional
graphs (they dont have to be rotatable/interactive after the
print out)?
The code is fairly simple and is listed down :
#libraries
library(RMySQL)
library(rgl)
library(scatterplot3d)
library(Rcmdr)
##############################################################################
#database connection
mycon<- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
#distinct sessions
rsSessionsU01<- dbSendQuery(mycon, "select distinct sessionID from
actiontimes where userID = 'ID01'")
sessionU01<-fetch(rsSessionsU01)
sessionU01[2,]
#user01 data
mycon<- dbConnect(MySQL(),
user='root',dbname='test',host='localhost',password='')
rsUser01<- dbSendQuery(mycon, "select
a.userID,a.sessionID,a.actionTaken,a.timelineMSEC,a.durationMSEC,b.X,b.Y,b.Rel__dist_,b.Total_dist_
from `actiontimes` as a , `ulogdata` as b where a.originalRECNO =
b.RECNO and a.userID='ID01'")
user01<- fetch(rsUser01, n= -1)
user01[1,1]
#plot loop
for (i in 1:10){
userSubset<-subset(user01,sessionID ==
sessionU01[i,],select=c(timelineMSEC,X,Y))
userSubset
x<-as.numeric(userSubset$X)
y<-as.numeric(userSubset$Y)
scatter3d(x,y,userSubset$timeline,xlim = c(0,1280), ylim =
c(0,1024),
zlim=c(0,1800000),type="h",main=sessionU01[i,],sub=sessionU01[i,])
tmp6=rep(".ps")
tmp7=paste(sessionU01[i,],tmp6,sep="")
tmp7
rgl.postscript(tmp7,"ps",drawText=FALSE)
#pdf(file=tmp7)
#dev.print(file=tmp7, device=pdf, width=600)
#dev.off(2)
}
______________________________________________
R-help at r-project.org <mailto:R-help at r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.