본문 바로가기
공부/R Programming

R 기초 - 그래픽 - 그래프 요소 추가

by 혼밥맨 2021. 1. 24.
반응형

R 기초 - 그래픽 - 그래프 요소 추가

 

 

# 제목과 축

?title

?par

?axis

 

str(state.x77)

states <- data.frame(state.x77)

attach(states)

 

old.par <- par(no.readonly=TRUE)

par(mar=c(5, 4, 4, 8) + 0.2)

 

plot(Murder, Life.Exp, pch=20, col="tomato", ylim=c(35,75)

      xaxt="n", col.axis="darkorchid4",

      cex.axis=0.75, ann=FALSE)

points(Murder, HS.Grad, pch=22, col="blue", bg="skyblue")

 

axis(side=2, at=seq(68, 76, 2), labels=seq(68, 76, 2),

      col.axis="red", cex.axis=0.75, las=2)

axis(side=4, at=seq(35, 70, 5), labels=seq(35, 70, 5),

      col.axis="blue", cex.axis=0.75, las=2, tck=-0.02)

 

mtext(text="High School\nGraduate\n(percent)",

        side=4, line=3, cex=0.9, las=2, col="tan4")

 

title(main="Murder vs Life Exp vs High School Grad",

      xlab="Murder (rate per 100,000 population)",

      ylab="Life Exp (years)",

      col.main="maroon", col.lab="tan4", cex.lab=0.9)

 

par(old.par)

detach(states)

 

# 범례

?legend

 

str(Orange)

tree1 <- subset(Orange, Tree==1)

tree2 <- subset(Orange, Tree==2)

xlim <- range(c(tree1$age, tree2$age))

ylim <- range(c(tree1$circumference, tree2$circumference))

 

plot(tree1$age, tree1$circumference, type="b",

      xlim=xlim, ylim=ylim,

      pch=16, lty=1, col="red",

      main="Growth of Oragne Tree",

      xlab="Age (days)", ylab="Circumference (mm)")

 

lines(tree2$age, tree2$circumference, type="b",

       pch=15, lty=2, col="blue")

 

legend("topleft", inset=0.05, title="Tree ID",

          legend=c("Tree 1", "Tree 2"),

          lty=c(1, 2), pch=c(16, 15), col=c("red", "blue"))

 

library(Hmisc)
minor.tick(nx=3, ny=3, tick.ratio=0.5)

 

 

# 텍스트

plot(1:5, 1:5, type="n", xaxt="n", yaxt="n", ann=FALSE)

text(2, 2, font=1, col="red", cex=1.0,

      labels="Default text: Sans text with plain (font=1)")

text(3, 3, font=2, col="darkgreen", cex=1.2, family="mono",

      labels="Mono text with bold (font=2)")

text(4, 4, font=3, col="blue", cex=1.4, family="serif",

      labels="Serif text with italic (font=4)")

text(2, 4, font=2, col="blue", cex=1.4, family="HersheyScript",

      labels="HersheyScript text (srt=25)", srt=25)

mtext(text="Windows Fonts: Sans, Mono, Serif, and HersheyScript",

        side=1, line=1, col="deeppink")

 

 

 

반응형

댓글