简体   繁体   中英

Adjust labels of second Y axis on the right of the plot

I have plotted the below graph but the cannot adjust the labels of the seconds Y axis. Does anybody have any idea how that is possible?

Also my right hand Y axis has limit from 1 to 14 *10^8 but when I set it, it only goes from zero to 1.4. Cannot find why!

Here is the code I used to make the plot

fdic <- data.frame(matrix(scan(text ="1   16.70833333 1329877000
2   17.20370370 1118256000
3   16.61111111 1047726000
4   19.05555556 972202000
5   15.50925926 269648386
6   0.07407407  248606000
7   3.00925926  220576899
8   5.83796296  188132575"), 8, 3, byrow = T))
colnames(fdic) <- c("id", "botnets_per_wk", "Deposits")

plot <- plot(fdic$id, fdic$botnets_per_wk, pch=16, axes=FALSE, ylim=c(0,25), xlab="", ylab="",
type="l",col="dark blue")
axis(2, col="black",las=1) 
mtext("Average # of botnets attacking banks per week",side=2,line=2.5)
box()
par(new=TRUE)
plot(fdic$id, fdic$Deposits, pch=15,  xlab="", ylab="", ylim=c(1,1400000000),
axes=FALSE, type="l", col="red")
mtext("Deposits (USD, logged)",side=4,col="red",line=4)
axis(4, ylim=c(1,1400000000), col="black",col.axis="black",las=1)
axis(1,at = seq(1, 50, by = 1))
mtext("bank",side=1,col="black",line=2.5)
legend("topleft",legend=c("Average # of botnets attacking banks per week","Deposits"),
text.col=c("black","red"),pch=c(16,15),col=c("black","red"))

Actually that "1.4" you see is 1.4e+09 , the scientific notation for 1.4 billion. Use options(scipen=999) to turn off scientific notation in R (this resets after reboot of R) and then adjust the left margins with par(mai=c(...)) for the long numbers to be completely visible:

fdic <- data.frame(matrix(scan(text ="1   16.70833333 1329877000
2   17.20370370 1118256000
3   16.61111111 1047726000
4   19.05555556 972202000
5   15.50925926 269648386
6   0.07407407  248606000
7   3.00925926  220576899
8   5.83796296  188132575"), 8, 3, byrow = T))
colnames(fdic) <- c("id", "botnets_per_wk", "Deposits")

options(scipen=999)

par(mai = c(1, 1, 1, 2))
plot <- plot(fdic$id, fdic$botnets_per_wk, pch=16, axes=FALSE, ylim=c(0,25), xlab="", ylab="", type="l",col="dark blue")
axis(2, col="black",las=1) 
mtext("Average # of botnets attacking banks per week",side=2,line=2.5)
box()
par(new=TRUE)
plot(fdic$id, fdic$Deposits, pch=15,  xlab="", ylab="", ylim=c(1,1400000000), axes=FALSE, type="l", col="red")
mtext("Deposits (USD, logged)",side=4,col="red",line=4)
axis(4, ylim=c(1,1400000000), col="black",col.axis="black",las=1)
axis(1,at = seq(1, 50, by = 1))
mtext("bank",side=1,col="black",line=2.5)
legend("topleft",legend=c("Average # of botnets attacking banks per week","Deposits"), text.col=c("black","red"),pch=c(16,15),col=c("black","red"))

在此处输入图片说明

But actually I would leave the 1.4 -scale and label that axis with "Deposits ( in billion US Dollar, logged)", because those long numbers with the many zeros are hard to read (I had to put my finger on them and count the zeros, and you don't want your readers to have to do that).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM