Plot
tikzDevice Support for native LaTeX output of R graphics
pgfSweave
require(plotrix)
gap.plot()
axis.break()
require(sfsmisc)
require(gplots)
plotCI : Plot Error Bars and Confidence Intervals
type=p,l,b,c,o,h,s,S,n,
layout()
par()
plot(d, type = "n")
polygon(d, col = "wheat")
for shading in regions between two lines on a plot, use polygon()
barplot()
rasterImage()
aa <- c("leukemia","Adip","Adip","Adipo","Age","Age","Aging","Aging","Aging","Aging","Aging","AIDS","AIDS","AIDS")
(xx <- table(aa))
barplot(xx)
#plot(b_arima$fitted,type ="l",col = "red")
par(mfrow=c(2,2))#divide plot in 2x2=4 parts
title(bquote( x %<=% .(x) ))
plot(forecast(x_arima,50),col = "red")
lines(b_arima$x,type ="l",col = "green")
legend(length(b_arima$fitted)*0.8,max(b_arima$fitted)*0.9,c("b_arima$x","b_arima$fitted"), cex=0.8,col=c("green","red"), pch=21:22, lty=1:2);
legend('topleft',c(expression(paste(alpha," = ", 1)),expression(paste(alpha," = ", 2))),text.col=c('black','red'))
c(expression(alpha == 1), expression(alpha == 2))
mytitle <- substitute(paste(delta^13,'C Station ', ival), list(ival=i))
title(eval(parse(text=paste("expression(paste(delta^13,'C Station ',",i,"))"))))
mytitle <- bquote(paste(delta^13,'C Station ', .(i)))
plot(1,1,main=bquote(delta^13~'C Station'~.(i)))
title(mytitle)
plot(1, main = bquote("Yield for " ~ italic(.(spp)) ~ "in management region" ~ .(region)))
plot(a,type ="l",col = "red",main="HEADING",ylab="YYYYY_YYYYY_YYYYY",xlab="XXXXX_XXXXX_XXXXX")
lines(b,type="o", pch=22, lty=2, col="red")
title(main="HEADING", col.main="red", font.main=4)
title(xlab="XXXXX_XXXXX_XXXXX", col.lab=rgb(0,0.5,0))
title(ylab="YYYYY_YYYYY_YYYYY", col.lab=rgb(0,0.5,0))
legend(1, g_range[2], c("Aa","Bb"), cex=0.8,col=c("blue","red"), pch=21:22, lty=1:2);
axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri"))
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1,labels=c("Mon", "Tue", "Wed", "Thu", "Fri"),xpd=T, cex=0.8)
box()
postscript("tmp.eps", onefile = TRUE)
pdf(file="figure.pdf", height=3.5, width=5)
png(filename="figure.png", height=295, width=300,bg="white")
dev.off()
barplot(..)
require(ggplot2)
x <- runif(100,1,2)
y <- runif(100,50,60)
z <- runif(100,99,100)
xyz <- melt(data.frame(x,y,z))
ggplot(xyz, aes(value)) + geom_histogram() + facet_grid(~ variable, scale="free")
plot(jitter(rep(1,300), 5), y, xlim=c(0,2) )
postscript("tmp.eps", onefile = TRUE)
qqnorm(rnorm(20))
dev.off()
plot 3 axis lables
plot(1:10, xaxt = "n")
axis(1, xaxp=c(2, 9, 7))
axis(4, labels=c("A", "B", "C", "D", "E"), at=seq(2, 10, by=2))
windowsFonts(calibri = windowsFont("Calibri"))
mosaic(UCBAdmissions, labeling_args = list(
gp_labels = gpar(fontsize = 12, fontfamily = "calibri"),
gp_varnames = gpar(fontsize = 16, fontfamily = "calibri")),
main = "Main title", main_gp = gpar(fontfamily = "calibri"),
sub = "Subtitle", sub_gp = gpar(fontfamily = "calibri"),
pop=FALSE)
labeling_cells(text = UCBAdmissions, clip = TRUE,
gp_text = gpar(fontfamily = "calibri"))(UCBAdmissions)
windowsFonts(myfont="Consolas")
par(family="myfont")
my.largs <- list(
gp_labels = gpar(fontsize = 12, fontfamily = "calibri"),
gp_varnames = gpar(fontsize = 16, fontfamily = "calibri"))
mosaic(UCBAdmissions, labeling_args=my.largs)
mosaic(UCBAdmissions, labeling_args=my.largs, shade=TRUE)
library(grid)
library(lattice)
set.seed(123)
print(xyplot(runif(10)~1:10, type="b"), position=c(0, .5, 1, 1), prefix="top", more=TRUE)
print(xyplot(runif(20)~1:20, type="l"), position=c(0, 0, .5, .5), prefix="left", more=TRUE)
print(xyplot(runif(20)~1:20, type="l"), position=c(.5, 0, 1, .5), prefix="right")
trellis.focus("panel", 1, 1, prefix="top")
grid.move.to(unit(4, "native"), unit(.9, "native"))
trellis.unfocus()
trellis.focus("panel", 1, 1, prefix="left", clip.off=TRUE)
grid.line.to(unit(10, "native"), unit(1, "native"))
trellis.unfocus()
layout(matrix(c(1,1,2,3), 2, 2, byrow = TRUE))
plot(runif(10), type='b', ylim=c(0,1))
x.tmp <- grconvertX(4, to='ndc')
y.tmp <- grconvertY(0.9, to='ndc')
plot(runif(20), type='l', ylim=c(0,1))
par(xpd=NA)
segments( 10, 1, grconvertX(x.tmp, from='ndc'), grconvertY(y.tmp, from='ndc'), col='red' )
plot(runif(20), type='l')
require(lattice)
trellis.device("pdf", width = 5, height = 5)
print(xyplot(0 ~ 0, main = "This title is not 'centered' for the human's eye", scales = list(alternating = c(1,1), tck = c(1,0))))
dev.off()
library(lattice)
trellis.device("pdf")
print(xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the human's eye", sub = "but subtitles are not centered", scales = list(alternating = c(1,1), tck = c(1,0))))
dev.off()
xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the human's eye", xlab = expression( atop(but~subtitles2~are~
underline(now)~centered, bold(bla) )), scales = list(alternating = c(1,1), tck = c(1,0)))
print(xyplot(0 ~ 0, xlab.top = "This title is now 'centered' for the human's eye", xlab = "but subtitles are _now_ centered\nbla", scales = list(alternating = c(1,1), tck = c(1,0))))
par(mai = c(3,1,1,1))
x <- runif(50)
plot(x, xlim = c(1, 500), ylim = c( -5, 1), bty = "l")
par(mai = c(2,1.5,2,1))
par(new = TRUE)
x <- runif(50)
plot(x, xlim = c(1, 500), ylim = c( -5, 1), bty = "l")
par(mai = c(1,2,3,1))
par(new = TRUE)
x <- runif(50)
plot(x, xlim = c(1, 500), ylim = c( -5, 1), bty = "l")
source("http://www.math.smith.edu/sasr/examples/wild-helper.R") # getting the boxplonts3 function
ds = read.csv("http://www.math.smith.edu/r/data/help.csv") # getting some data
female = subset(ds, female==1)
with(female,boxpoints3(pcs, homeless, "PCS", "Homeless")) # plotting...
x<-list(runif(90),runif(100),runif(80))
dendroPlot<-function(x,breaks=NA,nudge=NA) {
if(is.na(breaks[1]))
breaks=seq(min(unlist(x),na.rm=TRUE),
max(unlist(x),na.rm=TRUE),length.out=10)
plot(c(0,length(x)+1),range(unlist(x)),type="n")
if(is.na(nudge)) nudge<-strwidth("o")/2
for(list_element in 1:length(x)) {
binvar<-cut(x[[list_element]],breaks=breaks)
for(bin in 1:length(levels(binvar))) {
thisbin<-which(as.numeric(binvar)==bin)
offset<-(1:length(x[[list_element]][thisbin])-1)*nudge
offset[seq(2,length(offset),by=2)]<-
-offset[seq(2,length(offset),by=2)]
points(list_element+offset,sort(x[[list_element]][thisbin]))
}
}
}
dendroPlot(x)
Make.Funny.Plot <- function(x){
unique.vals <- length(unique(x))
N <- length(x)
N.val <- min(N/20,unique.vals)
if(unique.vals>N.val){
x <- ave(x,cut(x,N.val),FUN=min)
x <- signif(x,4)
}
# construct the outline of the plot
outline <- as.vector(table(x))
outline <- outline/max(outline)
# determine some correction to make the V shape,
# based on the range
y.corr <- diff(range(x))*0.05
# Get the unique values
yval <- sort(unique(x))
plot(c(-1,1),c(min(yval),max(yval)),
type="n",xaxt="n",xlab="")
for(i in 1:length(yval)){
n <- sum(x==yval[i])
x.plot <- seq(-outline[i],outline[i],length=n)
y.plot <- yval[i]+abs(x.plot)*y.corr
points(x.plot,y.plot,pch=19,cex=0.5)
}
}
x <- rnorm(1000)
Make.Funny.Plot(x)
boxplot(x, add = T, at = 0, col="#0000ff22") #https://stat.ethz.ch/pipermail/r-help/2007-October/142934.html
require(beeswarm)
?beeswarm
beeswarm(time_survival ~ event_survival, data = breast,method = 'smile', pch = 16, pwcol = as.numeric(ER),
xlab = '', ylab = 'Follow-up time (months)', labels = c('Censored', 'Metastasis'))
legend('topright', legend = levels(breast$ER),title = 'ER', pch = 16, col = 1:2)
## Install required packages
install.packages("ggplot2")
## load ggplot2 package
require(ggplot2)
## make up some example data
## note that this is typically your job as a poster
set.seed(10) # so we get the same pseudorandom data
dat <- data.frame(S1 = sample(1:1000, size = 5000, TRUE), S2 = sample(seq(1, 1000, by = 100), 5000, TRUE))
## look at the str()ucture of the data frame, 'dat'
str(dat)
## get a simple summary
summary(dat)
## plot histograms side by side
par(mfrow = c(1, 2))
hist(dat$S1)
hist(dat$S2)
## melt data frame for ggplot2
mdat <- melt(dat)
## look at its structure and look at the first few rows
str(mdat)
head(mdat)
## basic histogram of *all* data
## hmm, not really what we want
ggplot(data = mdat, aes(value)) + geom_histogram()
## To tell the variables apart, we will colour the bars
## (by setting their fill colour) to which variable
ggplot(data = mdat, aes(value)) + geom_histogram(aes(fill = variable))
## The default position is stacked, but you said side by side
## so we will "dodge" the bars
ggplot(data = mdat, aes(value)) + geom_histogram(aes(fill = variable), position = "dodge")
## this is getting close, but what about the scale?
## we can transform the scale, note how the values do not change
## rather the y axis scale changes
ggplot(data = mdat, aes(value)) + geom_histogram(aes(fill = variable), position = "dodge") + scale_y_sqrt()
## achieves a similar result by changing the coordinates
ggplot(data = mdat, aes(value)) + geom_histogram(aes(fill = variable), position = "dodge") + coord_trans(ytrans = "sqrt")
3D plot
x <- c(-4, -2, 0, 2, 4)
y <- c(-4, 0, 2, -3, 1)
z <- c(-2, 6, -3, 5, 5)
library(rgl)
plot3d(x, y, z, xlim=c(-5,7), ylim=c(-5,3), zlim=c(-4,7), xlab="PC1",
ylab="PC2", zlab="PC3", col=1, type="n")
text3d(x, y, z, col=1, "o")
text3d(x+1, y+0.5, z, col=2, "*")
text3d(x-0.5, y, z-0.5, col=3, "w")