#Elements in the human Body #chemical symbols symbols = c("O", "C", "H", "N", "Ca", "P", "K", "S", "Na", "Cl", "Mg") #chemical names names = c("Oxygen", "Carbon", "Hydrogen", "Nitrogen", "Calcium", "Phosphorus", "Potassium", "Sulfur", "Sodium", "Chlorine", "Magnesium") #atomic numbers number = c(8, 6, 1, 7, 20, 15, 19, 16, 11, 17, 12) #percentage by weight in human body percents = c(65, 18.5, 9.5, 3.3, 1.5, 1.0, 0.4, 0.3, 0.2, 0.2, 0.1) # combine into a data frame body = data.frame(symbols, names, number, percents) # make into a pie chart #cex controls font size #radius the size of the pie chart pie(body$percents, labels = body$symbols, cex=0.5, radius= 1.05, main="Elements in the Body",col=rainbow(11)) ### # too many overlapping labels ### # use legend instead of labels # pie(body$percents, cex=0.5, radius= 0.95, main="Elements in the Body",col=rainbow(11)) legend("topright", legend=body$symbols, cex = 0.8, fill=rainbow(11)) ### # install the plotrix libary # try a #3d version # can alos just check it under Packages # library(plotrix) # pie3D(body$percents, labels = body$symbols, cex=0.5, radius= 1.05, main="Elements in the Body",col=rainbow(11)) # # try legend instead of label # pie3D(body$percents, cex=0.5, radius= 0.95, main="Elements in the Body",col=rainbow(11)) legend("topright", legend=body$symbols, cex = 0.8, fill=rainbow(11))