library("maps")
require(ggplot2)
library(ggsubplot)
world.map <- map("world", plot = FALSE, fill = TRUE)
world_map <- map_data("world")
require(lattice)
require(latticeExtra)
# Calculate the mean longitude and latitude per region (places where subplots are plotted)
library(plyr)
cntr <- ddply(world_map,.(region),summarize,long=mean(long),lat=mean(lat))
# example data
myd <- data.frame (region = c("USA","China","USSR","Brazil", "Australia","India", "Nepal", "Canada",
"South Africa", "South Korea", "Philippines", "Mexico", "Finland",
"Egypt", "Chile", "Greenland"),
frequency = c(501, 350, 233, 40, 350, 150, 180, 430, 233, 120, 96, 87, 340, 83, 99, 89))
subsetcntr <- subset(cntr, region %in% c("USA","China","USSR","Brazil", "Australia","India", "Nepal", "Canada",
"South Africa", "South Korea", "Philippines", "Mexico", "Finland",
"Egypt", "Chile", "Greenland"))
simdat <- merge(subsetcntr, myd)
colnames(simdat) <- c( "region","long","lat", "myvar" )
panel.3dmap <- function(..., rot.mat, distance, xlim,
ylim, zlim, xlim.scaled, ylim.scaled, zlim.scaled) {
scaled.val <- function(x, original, scaled) {
scaled[1] + (x - original[1]) * diff(scaled)/diff(original)
}
m <- ltransform3dto3d(rbind(scaled.val(world.map$x,
xlim, xlim.scaled), scaled.val(world.map$y, ylim,
ylim.scaled), zlim.scaled[1]), rot.mat, distance)
panel.lines(m[1, ], m[2, ], col = "green4")
}
p2 <- cloud(myvar ~ long + lat, simdat, panel.3d.cloud = function(...) {
panel.3dmap(...)
panel.3dscatter(...)
}, type = "h", col = "red", scales = list(draw = FALSE), zoom = 1.1,
xlim = world.map$range[1:2], ylim = world.map$range[3:4],
xlab = NULL, ylab = NULL, zlab = NULL, aspect = c(diff(world.map$range[3:4])/diff(world.map$range[1:2]),
0.3), panel.aspect = 0.75, lwd = 2, screen = list(z = 30,
x = -60), par.settings = list(axis.line = list(col = "transparent"),
box.3d = list(col = "transparent", alpha = 0)))
print(p2)
# Over US map
library("maps")
state.map <- map("state", plot = FALSE, fill = FALSE)
require(lattice)
require(latticeExtra)
# data
state.info <- data.frame(name = state.name, long = state.center$x,
lat = state.center$y)
set.seed(123)
state.info$yvar<- rnorm (nrow (state.info), 20, 5)
panel.3dmap <- function(..., rot.mat, distance, xlim,
ylim, zlim, xlim.scaled, ylim.scaled, zlim.scaled) {
scaled.val <- function(x, original, scaled) {
scaled[1] + (x - original[1]) * diff(scaled)/diff(original)
}
m <- ltransform3dto3d(rbind(scaled.val(state.map$x,
xlim, xlim.scaled), scaled.val(state.map$y, ylim,
ylim.scaled), zlim.scaled[1]), rot.mat, distance)
panel.lines(m[1, ], m[2, ], col = "grey40")
}
pl <- cloud(yvar ~ long + lat, state.info, subset = !(name %in%
c("Alaska", "Hawaii")), panel.3d.cloud = function(...) {
panel.3dmap(...)
panel.3dscatter(...)
}, col = "blue2", type = "h", scales = list(draw = FALSE), zoom = 1.1,
xlim = state.map$range[1:2], ylim = state.map$range[3:4],
xlab = NULL, ylab = NULL, zlab = NULL, aspect = c(diff(state.map$range[3:4])/diff(state.map$range[1:2]),
0.3), panel.aspect = 0.75, lwd = 2, screen = list(z = 30,
x = -60), par.settings = list(axis.line = list(col = "transparent"),
box.3d = list(col = "transparent", alpha = 0)))
print(pl)
The blog is a collection of script examples with example data and output plots. R produce excellent quality graphs for data analysis, science and business presentation, publications and other purposes. Self-help codes and examples are provided. Enjoy nice graphs !!
Labels
2d
(1)
3 vartiable plots
(5)
3D plots
(8)
arch
(1)
area
(1)
association plot
(4)
bar
(1)
barchart
(13)
bean plot
(1)
beeswarm
(1)
binormial
(1)
biplot
(1)
box-percentile
(2)
box-whisker plot
(1)
boxplot
(10)
bubble plot
(5)
calendar
(1)
categorical data
(6)
centepede plot
(1)
circle
(2)
circular
(1)
cluster
(4)
color
(2)
colour
(1)
combination plot
(10)
countur
(1)
cross bar
(1)
cumulative
(1)
curve
(3)
dendogram
(3)
density
(13)
diagram
(2)
distribution
(9)
ditribution
(1)
dot plot
(1)
double axis
(1)
ellipse
(2)
error bar
(6)
factor plot
(3)
fluctutation diagram
(1)
google
(1)
grid plot
(1)
heatmap
(20)
hexabin plot
(1)
histogram
(11)
hive
(1)
kernel density
(4)
ladder plot
(2)
large data points
(4)
level plot
(1)
line plot
(3)
line range
(1)
manhattan plot
(1)
map
(13)
mosaic plot
(1)
normal
(2)
notched
(1)
parallel plot
(1)
pedigree plot
(1)
phylogentic tree
(1)
piechart
(3)
points
(2)
polar
(1)
Q-Q plot
(1)
raster
(2)
regression line
(3)
ribbon plot
(1)
rootogram
(1)
rugs
(2)
scale plot
(1)
scenes
(1)
shaded
(1)
spatial plot
(2)
sphere
(1)
spike histogram
(1)
Spine plot
(1)
stacked bar
(1)
Sunflower
(1)
ternary plot
(1)
text only
(1)
timeseries
(6)
trellis plot
(8)
two axis
(1)
vinn diagram
(1)
voilin plot
(2)
wireframe plot
(1)
xy barplot
(4)
xy line
(10)
xy points
(25)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.