![Page 1: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/1.jpg)
R (3)
Introduction to Graphics
![Page 2: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/2.jpg)
The main guide
R in ActionData Analysis and Graphics with RRobert I. Kabacoff
http://www.manning.com/affiliate/idevaffiliate.php?id=1102_173
![Page 3: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/3.jpg)
Simple plot• Evolution of daily sales in August 2011 (data imported from Pg)> plot(daily_sales_2011_8$day,+ daily_sales_2011_8$sales, type="b")
![Page 4: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/4.jpg)
Parameters for symbols and lines
![Page 5: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/5.jpg)
Plot with symbol and line• Evolution of daily sales in August 2011 (data imported from Pg)> plot(daily_sales_2011_8$day,+ daily_sales_2011_8$sales, + type="b", + lty=2, + pch=17)
![Page 6: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/6.jpg)
Plot with symbol,line and different symbol size• Evolution of daily sales in August 2011 (data imported from Pg)> plot(daily_sales_2011_8$day,+ daily_sales_2011_8$sales, + type="b", + lty=2, + pch=17,+ cex = .5)
![Page 7: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/7.jpg)
Parameters for color
![Page 8: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/8.jpg)
Plot with colour> plot(daily_sales_2011_8$day,+ daily_sales_2011_8$sales, + type="b", + lty=2, + pch=17,+ cex = .5,+ col="brown", + col.axis=+ "green", + col.lab=+ "red", + fg="blue", + bg="yellow")
![Page 9: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/9.jpg)
Parameters for text s& dimensions/margins
![Page 10: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/10.jpg)
Parameters for text & dimensions/margins
![Page 11: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/11.jpg)
Change axes limits
> plot(daily_sales_2011_8$day,daily_sales_2011_8$sales/+ 1000, xlim=c(min(daily_sales_2011_8$day), + max(daily_sales_2011_8$day)), ylim=c(0, + max(daily_sales_2011_8$sales/1000)+1000),+ type="b", + cex = .5,+ col="red", + lty=2, + pch=2, + lwd=2)
![Page 12: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/12.jpg)
Titles (1)
• Types of titles– Main title of the graphic (main)– Sub-title of the graphic (sub)– Title of the axis x and y (xlab and ylab)
> title(main="main title", + sub="sub-title",+ xlab="x-axis label", + ylab="y-axis label")
![Page 13: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/13.jpg)
Titles (2)> plot(dday, sales/1000, main= "Daily Sales in + August 2011", sub="Data imported from + PostgreSQL", xlab="Day (of the month)",+ ylab="Sales (thousands)",+ type="b", + cex = .5,+ col="red",+ lty=2, + pch=2, + lwd=2)
![Page 14: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/14.jpg)
Legend (1)> attach(daily_sales_2011_8)> plot(day, sales/1000, main="Daily Sales - Aug. vs. Sept. 2011", sub="Data imported from PostgreSQL", xlab="Day (of the month)", ylab="Sales(thousands)", type="b", cex = 1.25, col="red", lty=1, pch=2, lwd=1.5)> detach(daily_sales_2011_8)> attach(daily_sales_2011_9)> # to display on the same graphic, use lines, not plot > lines(day, sales/1000, col="black", lty=2, + pch=17, lwd=2)# now the legendlegend("bottomright", inset=.05, title="Month", + c("Aug","Sept"),+ lty=c(1, 2), pch=c(2, 17), col=c("red", "black"))
![Page 15: R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff](https://reader035.vdocuments.net/reader035/viewer/2022062518/5697bf991a28abf838c91707/html5/thumbnails/15.jpg)
Legend (2)