Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Region1 Region2
- 2007 17 55
- 2008 26 43
- 2009 53 70
- 2010 96 58
- > test <- read.table("/tmp/data.txt")
- > png(filename="/tmp/test.png", height=1000, width=750, bg="white", res=300)
- > plot(test$Region1, type="b", col="blue", ylim=c(0,100), lwd=3)
- > lines(test$Region2, type="b", col="red", lwd=3)
- > dev.off()
- > d <- read.table("/tmp/data.txt")
- > png <- png(filename="/tmp/test.png", height=1000, width=750)
- > myLayout <- loadPredefinedLayout("NiceKeynoteLayout")
- > coolplot(d, layout=myLayout, out=png)
- data <- data.frame(Year=seq(as.Date("2007-01-01"),
- as.Date("2010-01-01"), by="year"),
- Region1=c(17,26,53,96), Region2=c(55,43,70,58))
- library(ggplot2)
- # Convert data to a form optimised for visualisation, not
- # data entry
- data2 <- melt(data, measure = c("Region1", "Region2"))
- # Define the visualisation you want
- ggplot(data2, aes(x = Year, y = value, colour = variable)) +
- geom_line()
- test <- read.table("/tmp/test.txt", header=TRUE)
- png(filename="/tmp/test.png", height=750, width=1000,
- bg="white", res=300)
- par(mar=c(2.5,2.5,0.75,0.75),
- family="Gill Sans", font=1, # font 2 would be bold
- cex=0.75, cex.lab=0.75, cex.axis=0.75)
- mymax <- max(test$Region1, test$Region2)*1.25
- plot(test$Region1, type="b", col="#304E67",
- ylim=c(0, mymax), lwd=3,
- bty="l", axes=FALSE, ann=FALSE, cex=1.0, tck=1)
- axis(1, lwd.ticks=0, at=1:length(test$Year), lab=test$Year)
- axis(2, lwd=0, las=1, at=c(0,25,50,75,100), yaxp=c(0,100,4))
- # grid(nx = NA, ny = 5, col = "lightgray") # wrong, see axTicks
- for(y in c(25, 50, 75, 100)) {
- lines(rep(y, length(test$Region1)), type="l", col="lightgray", lwd=1)
- }
- lines(test$Region1, type="b", col="#304E67", lwd=3)
- lines(test$Region2, type="b", col="#974449", lwd=3)
- # title(xlab="Year", col.lab=rgb(0,0.5,0))
- # title(ylab="Output", col.lab=rgb(0,0.5,0))
- legend(1, mymax+8, c("Region 1","Region 2"), cex=0.75,
- col=c("#304E67" ,"#974449"),
- pch=1:1, # circles
- lty=1:1, # solid
- lwd=1.5, # line width
- bty="n") # no box around
- dev.off()
- Year Region1 Region2
- 2007 17 55
- 2008 26 43
- 2009 53 70
- 2010 96 58
- R> data <- data.frame(Year=seq(as.Date("2007-01-01"),
- as.Date("2010-01-01"), by="year"),
- Region1=c(17,26,53,96), Region2=c(55,43,70,58))
- R> data
- Year Region1 Region2
- 1 2007-01-01 17 55
- 2 2008-01-01 26 43
- 3 2009-01-01 53 70
- 4 2010-01-01 96 58
- R> par(mar=c(3,4,1,1))
- R> plot(data$Year, data$Region1, type='l', col='blue', ylab="Values")
- R> lines(data$Year, data$Region2, col='red')
- R>
- plot <- ggplot(data2, aes(Year, value, group = variable,
- colour = variable)) + geom_line(size = 1) +
- opts(legend.position = "none")
- plot <- plot + geom_point () + opts(legend.position = "none")
- plot + geom_text(data = data2[data2$year == 2010,
- ], aes(label = variable), hjust = 1.2, vjust = 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement