Using the function we can zero out the x and y axes.
plot(x=1:10,y=1:10)
plot(x=1:10,y=1:10,yaxs="i", ylim=c(0,10),xlim=c(0,10),xaxs="i")
Make a plot to add some text
plot(1:10, 1:10)
text(5,5, "my text here")
The above line adds the string in quotes at x=5, y=5.
Setting the resolution of figures in R can be a bit tricky. The easiest way to do it is to use a the graphic wrappers (e.g., jpeg(), tiff(), png(), bmp()). These are placed in front of the plotting commands to 'set the stage'.
Here is an example: a figure 4x4 inches with a resolution of 800 dpi. The width and height arguments do as you would expect and set the figure dimensions. The units specifies that are working in inches and the resolution is set at 800 pixels per inch (the more the better). Most
In order to set the resolution, have not set the width/height and the resolution argument controls how many pixels per inch (PPI which is often used similarly to DPI). So if you want 800 DPI and you want it to be a 4 x 4 inch graph something like:
tiff(file = "temp2.tiff", width = 4, height = 4, units = "in", res = 800)
plot(1:10, 1:10)
dev.off()
same for a jpeg
jpeg(file = "temp2.jpeg", width = 4, height = 4, units = "in", res = 800)
plot(1:10, 1:10)
dev.off()
# alternatively this does what you might expect
doy<- c(1:365)
new<- as.Date(doy, origin="2012-12-31")
format(new[1],"%j")
Do be careful as R treas a 0 as the origin and 1 as the next day from the origin....
Here is what is going on… if you get errors that look like this while using R on Umbrella
> require(RODBC)
Loading required package: RODBC
Warning message:
package 'RODBC' was built under R version 2.13.2
> com_line<- odbcConnectAccess2007("C:/.../my_database.accdb")
Warning messages:
1: In odbcDriverConnect(con, ...) :
[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
2: In odbcDriverConnect(con, ...) : ODBC connection failed
The problem is as follows...
1) Umbrella is using 64-bit MS office software
2) The R shortcut by default opens 32-bit R
3) 32-bit R and 64-bit Office do not play together at all!
4) 64-bit R and 64-bit Office do play well together
So in Umbrella if you go to programsàStatisticsàRàR x64.2.13.0 will open 64-bit R and will talk to the database. All the code we looked at should work if the 64-bit R is used. This is a very odd quirk…
Issue: save.image and a subset of objects
> a<- 6
> b<- 5
> z<- 56
> save.image("dat.Rdata", list=c('a','b'))
Error in save.image("dat.Rdata", list = c("a", "b")) :
unused argument(s) (list = c("a", "b"))
> save(a,b,"dat.Rdata")# works
The function save.image() is a short-cut for save(list =ls(all=TRUE), file=".RData").
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
Error: package ‘rJava’ could not be loaded
After a bit of Googling I discovered that I needed to have both the 32-bit and 64-bit versions of Java installed on my computer for xlsx to work properly. I’m running 64-bit Windows 7 and 64-bit RStudio, but Firefox only requires the 32-bit Java. I had to go to this page (http://www.java.com/en/download/manual.jsp) and manually install the 64-bit Java. After doing that, the xlsx package ran just fine and without errors!
Just in case any other students come across this problem when trying to complete the first assignment, this was the solution that worked for me. Thanks!