User Tools

Site Tools


how_to_make_a_graph_that_has_two_y-axis
sample <- read.csv("./adwords_clusters.csv")

I change the lable into sequence before I create an ordered sequence

sample$id  <- 1:nrow(sample) 
time <- seq(sample$id)

plot cost, defining the plot area mar stand for “margin” and the four numbers mean space to DOWN, LEFT, UP, RIGHT in the order.

par(mar=c(5, 10, 3, 1) + 0.1)  
 
plot(sample$Cost, axes=F, type="l", ylim=c(0,max(sample$Cost)), xlab="", ylab="",col="black", main="")
points(sample$Cost, pch=1, col="black")
axis(2, ylim=c(0,max(sample$Cost)),col="black",lwd=1)
mtext(2,text="cost",line=2)

Plot the second line

par(new=T)
plot(sample$cli, axes=F, ylim=c(0,max(sample$cli)), xlab="", ylab="", type="l",lty=2, main="",lwd=2, col="black")
points(sample$cli, pch=4, col="black")
axis(2, ylim=c(0,max(sample$cli)),lwd=1,line=3.5)
mtext(2,text="clicks",line=5.5)

lty stands for “line type” and decide the type. lwd means “line width”.

axis(1,pretty(range(time),5))
mtext("sample",side=1,col="black",line=2,cex=1)
how_to_make_a_graph_that_has_two_y-axis.txt · Last modified: 2015/07/28 19:25 by vincenzo