0% found this document useful (0 votes)
19 views

Class 4 - Pie, Barplot

Uploaded by

Roli Dube
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Class 4 - Pie, Barplot

Uploaded by

Roli Dube
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

> colors = c("Silver", "Black", "White", "Grey", "Red","Blue", "Brown", "Other")

> percentage= c(26,24,16,16,6,5,4,3)

> colors

[1] "Silver" "Black" "White" "Grey" "Red" "Blue" "Brown" "Other"

> percentage

[1] 26 24 16 16 6 5 4 3

> cbind (colors,percentage)

colors percentage

[1,] "Silver" "26"

[2,] "Black" "24"

[3,] "White" "16"

[4,] "Grey" "16"

[5,] "Red" "6"

[6,] "Blue" "5"

[7,] "Brown" "4"

[8,] "Other" "3"

> pie (percentage)

> pie (percentage)

> names (percentage)= colors

> percentage

Silver Black White Grey Red Blue Brown Other

26 24 16 16 6 5 4 3

> pie (percentage)

> percentage

Silver Black White Grey Red Blue Brown Other

26 24 16 16 6 5 4 3

> carcol = c("#C0C0C0", "black", "white", "#696969", "red", "blue", "brown","#FDE68C")

> pie (percentage, col = carcol)


> pie (percentage, col = carcol, main= "Pie chart of Auto Color Prefrence")

pie (percentage, label = colors)

> pie (percentage, label = colors, col= carcol)

> pie (percentage, label = colors, col = carcol, main= "Pie chart of Auto Color Prefrence")

>

> lbl = paste (colors, " ", percentage, "%")

> lbl

[1] "Silver 26 %" "Black 24 %" "White 16 %" "Grey 16 %" "Red 6 %"

[6] "Blue 5 %" "Brown 4 %" "Other 3 %"

> pie (percentage, label = lbl, col = carcol, main= "Pie chart of Auto Color Prefrence")

Install library using plotrix

> library (plotrix)

> pie3D (percentage, labels = lbl, col = carcol, main= "Pie chart of Auto Color Prefrence")

> pie3D (percentage, labels = lbl, col = carcol, explode= 0.1, main= "Pie chart of Auto Color Prefrence")

> pie3D (percentage,col = carcol, explode= 0.1, main= "Pie chart of Auto Color Prefrence")

> legend ("topleft", lbl)

> legend ("topleft", lbl)

> legend ("topright", lbl)

> lbl

[1] "Silver 26 %" "Black 24 %" "White 16 %" "Grey 16 %" "Red 6 %"

[6] "Blue 5 %" "Brown 4 %" "Other 3 %"

> dev.off

function (which = dev.cur())

if (which == 1)

stop("cannot shut down device 1 (the null device)")

.External(C_devoff, as.integer(which))
dev.cur()

<bytecode: 0x04e2e4c0>

<environment: namespace:grDevices>

> dev.off ()

null device

> pie3D (percentage,col = carcol, explode= 0.1, main= "Pie chart of Auto Color Prefrence")

BARPLOT
> barplot (percentage, col= carcol, main = "bar graph")

> legend ("topright", lbl, cex=0.5, fill= carcol)

> dev.off()

null device

> barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE)

> legend ("topright", lbl, cex=0.5, fill= carcol)

> dev.off()

null device

> barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE, names.arg = colors)

> dev.off()

null device

> barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE, names.arg = colors, las =1)

> dev.off()

null device

1
> barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE, names.arg = colors, las =1, xlab
="percentage", ylab= "colors")

> barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE, names.arg = colors, las =1, xlab
="percentage", ylab= "colors", density = 50, border = "darkblue")

barplot (percentage, col= carcol, main = "bar graph", horiz = TRUE, names.arg = colors, las =1, xlab
="percentage", ylab= "colors", density = c(5,10,15,20,30,7), border = "darkblue")

You might also like