Presentation is loading. Please wait.

Presentation is loading. Please wait.

R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff

Similar presentations


Presentation on theme: "R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff"— Presentation transcript:

1 R (3) Introduction to Graphics

2 The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff http://www.manning.com/affiliate/idevaffiliate.php?id=1102_173

3 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")

4 Parameters for symbols and lines

5 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)

6 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)

7 Parameters for color

8 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")

9 Parameters for text s& dimensions/margins

10 Parameters for text & dimensions/margins

11 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)

12 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")

13 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)

14 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 legend legend("bottomright", inset=.05, title="Month", + c("Aug","Sept"), + lty=c(1, 2), pch=c(2, 17), col=c("red", "black"))

15 Legend (2)


Download ppt "R (3) Introduction to Graphics. The main guide R in Action Data Analysis and Graphics with R Robert I. Kabacoff"

Similar presentations


Ads by Google