Graphics Programs Reference
In-Depth Information
x y
Min. :-1.299 Min. :6.479e-06
1st Qu.:14.786 1st Qu.:1.433e-03
Median :30.870 Median :1.466e-02
Mean :30.870 Mean :1.553e-02
3rd Qu.:46.954 3rd Qu.:2.646e-02
Max. :63.039 Max. :4.408e-02
The write.table()
function saves
new files in your
current working
directory. Change
your working
directory via the
main menu or with
setwd() .
The main thing you care about is the x and y . That shows the breakdown of
the coordinates, but if you want to access all of them you could enter the
following.
d2008$x
d2008$y
Then to store them in a text file, use write.table() . As arguments, it takes
the data you want to save, the filename you want to save it as, the separa-
tor you want to use (for example, comma or tab), and some others. To save
the data as a basic tab-delimited text file, do the following.
If you like to do
your plotting with
different software
other than R but
want to make use
of R's computing
functionality, you
can save any or all
of your results with
write.table() .
d2008frame <- data.frame(d2008$x, d2008$y)
write.table(d2008frame, “birthdensity.txt”, sep=”\t”)
The file birthdensity.txt should now be available in your working directory.
If you don't want the rows to be numbered and a comma as the separator
instead of tabs, you can do that just as easily.
write.table(d2008frame, “birthdensity.txt”, sep=”,”, row.names=FALSE)
Now you can load that data into excel, Tableau, Protovis, or whatever you
want that accepts delimited text, which is just about everything.
Back to the actual density plot. Remember, you already have the coordi-
nates for your density plot. You just have to put them in graph form with,
naturally, the plot() function. Figure 6-29 shows the result.
plot(d2008)
You can also make a filled density plot if you want, using plot() along with
polygon() , as shown in Figure 6-30. You use the former to set the axes, but
with the type set to “n” for no plotting. Then use the latter to actually draw
the shape; set the fill color to a dark red and the border to a light gray.
plot(d2008, type=”n”)
polygon(d2008, col=”#821122”, border=”#cccccc”)
Search WWH ::




Custom Search