showkey
showkey

Reputation: 298

How to set the second x-aixs in the graph?

x <- seq(0.5, 0.9, length = 400)
y <- dnorm(x,0.7,0.0458)
plot(x, y, type="l",  yaxt="n",ann=FALSE,bty="n", xaxt="n")
axis(1, at=seq(0.5,0.9,by=0.1), labels=c("","",0.7, 0.8, 0.9) )
mtext("Proportions", 1, at=0.9, line=2)
xx=c(0.8,seq(0.8,0.9,length=100),0.9)
yy= c(0,dnorm(seq(0.8,0.9,length=100),0.7,0.0458),0)
polygon(xx, yy, col = "gray", border = NA)

I get a good graph(graph1.jpg) with the code,how can i create the second line on the graph1.jpg,to change graph1.jpg into graph2.jpg?

This is a graph1.jpg. enter image description here

This is a graph2.jpg. enter image description here

Upvotes: 0

Views: 136

Answers (1)

Didzis Elferts
Didzis Elferts

Reputation: 98569

For the function axis() there is an argument line= that determine in which line under plot axis is drawn. Setting this argument, for example, to line=4 you can add another axis. But before plot() you should change margin setting to get more space under x axis with par(mar=...)).

par(mar=c(8,3,3,3))
x <- seq(0.5, 0.9, length = 400)
y <- dnorm(x,0.7,0.0458)
plot(x, y, type="l",  yaxt="n",ann=FALSE,bty="n", xaxt="n")
#First x axis
axis(1, at=seq(0.5,0.9,by=0.1), labels=c("","",0.7, 0.8, 0.9) )
mtext("Proportions", 1, at=0.9, line=2)
#Second x axis 
axis(1, line=4,at=seq(0.5,0.9,by=0.1), labels=c("","",0, 2.18, 3) )
mtext("z score", 1, at=0.9, line=6)

enter image description here

Upvotes: 1

Related Questions