# Load data
data("mtcars")
df <- mtcars
df$cyl <- as.factor(df$cyl)
df$name <- rownames(df)
head(df[, c("wt", "mpg", "cyl")], 3)
# Basic plot
ggdotchart(df, x = "mpg", label = "name" )
# Change colors by group cyl
ggdotchart(df, x = "mpg", label = "name",
group = "cyl", color = "cyl",
palette = c('#999999','#E69F00','#56B4E9') )
# Use brewer palette
ggdotchart(df, x = "mpg", label = "name",
group = "cyl", color = "cyl", palette = "Dark2" )
# Change the orientation
# Sort in ascending order
ggdotchart(df, x = "mpg", label = "name",
group = "cyl", color = "cyl",
palette = c("#00AFBB", "#E7B800", "#FC4E07"),
orientation = "horizontal", sorting = "ascending" )
Run the code above in your browser using DataLab