Create Dot Charts in R Programming – dotchart () Function

dotchart() function in R Language is used to create a dot chart of the specified data. A dot chart is defined as a plot which is used to draw a Cleveland dot plot.

Syntax:
dotchart(x, labels = NULL, groups = NULL,
gcolor = par(“fg”),
color = par(“fg”))

Parameters:
x: it is defined as numeric vector or matrix
labels: a vector of labels for each point.
groups: a grouping variable indicating how the elements of x are grouped.
gcolor: color to be used for group labels and values.
color: the color(s) to be used for points and labels.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Dot chart of a single numeric vector
dotchart(mtcars$mpg, labels = row.names(mtcars),
         cex = 0.9, xlab = "mpg")

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Plot and color by groups cyl
grps <- as.factor(mtcars$cyl)
my_cols <- c("blue", "darkgreen", "orange")
dotchart(mtcars$mpg, labels = row.names(mtcars),
         groups = grps, gcolor = my_cols,
         color = my_cols[grps],
         cex = 0.9,  pch = 22, xlab = "mpg")

chevron_right


Output:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.