r - Labeling a dotchart -


given following example , chart, how 1 able plot exact value of x axis next each points?

x <- mtcars[order(mtcars$mpg),] # sort mpg x$cyl <- factor(x$cyl) # must factor x$color[x$cyl==4] <- "red" x$color[x$cyl==6] <- "blue" x$color[x$cyl==8] <- "darkgreen"     dotchart(x$mpg,labels=row.names(x),cex=.7,groups= x$cyl,  main="gas milage car models\ngrouped cylinder",    xlab="miles per gallon", gcolor="black", color=x$color) 

i tried modifying labels argument, adjusts y axis label name.

you'll need sort category, x. can use text ricardo suggests, accounting breaks between categories.

x <- mtcars[order(-mtcars$cyl, mtcars$mpg),] # sort category, position within category  # above x$cyl <- factor(x$cyl) # must factor x$color[x$cyl==4] <- "red" x$color[x$cyl==6] <- "blue" x$color[x$cyl==8] <- "darkgreen"     dotchart(x$mpg,labels=row.names(x),cex=.7,groups= x$cyl,          main="gas milage car models\ngrouped cylinder",          xlab="miles per gallon", gcolor="black", color=x$color)  # adding text text(x = x$mpg,      y = 1:nrow(x) + ifelse(x$cyl == "6", 2, ifelse(x$cyl == "4", 4, 0)),      labels= x$mpg,      cex = 0.5,      pos = 4) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -