{"id":1120,"date":"2019-11-08T17:14:19","date_gmt":"2019-11-09T00:14:19","guid":{"rendered":"http:\/\/www.zhuoyao.net\/?p=1120"},"modified":"2019-11-08T17:14:19","modified_gmt":"2019-11-09T00:14:19","slug":"ggpubr-publication-ready-plots","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2019\/11\/08\/ggpubr-publication-ready-plots\/","title":{"rendered":"ggpubr: Publication Ready Plots"},"content":{"rendered":"\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/\">http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/<\/a><\/p>\n\n\n\n<p>The <strong>ggpubr<\/strong> R package facilitates the creation of beautiful ggplot2-based graphs for researcher with non-advanced programming backgrounds.<\/p>\n\n\n\n<p>The current material starts by presenting a collection of articles \nfor simply creating and customizing publication-ready plots using \nggpubr. Next, some examples of plots created with ggpubr are shown.<\/p>\n\n\n\n<p>ggpubr Key features:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Wrapper around the <strong>ggplot2<\/strong> package with a <strong>less opaque syntax<\/strong> for beginners in R programming.<\/li><li>Helps researchers, with non-advanced R programming skills, to create easily <strong>publication-ready plots<\/strong>.<\/li><li>Makes it possible to automatically <strong>add p-values and significance levels<\/strong> to box plots, bar plots, line plots, and more.<\/li><li>Makes it easy to <strong>arrange and annotate multiple plots<\/strong> on the same page.<\/li><li>Makes it easy to <strong>change grahical parameters<\/strong> such as colors and labels.<\/li><\/ul>\n\n\n\n<p>Official online documentation: <a href=\"http:\/\/www.sthda.com\/english\/rpkgs\/ggpubr\">http:\/\/www.sthda.com\/english\/rpkgs\/ggpubr<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/images\/ggpubr\/ggpubr.png\" alt=\"ggpubr: publication ready plots\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Install and load ggpubr<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Install from <a href=\"https:\/\/cran.r-project.org\/package=ggpubr\">CRAN<\/a> as follow:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>install.packages(\"ggpubr\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Or, install the latest version from <a href=\"https:\/\/github.com\/kassambara\/ggpubr\">GitHub<\/a> as follow:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Install\nif(!require(devtools)) install.packages(\"devtools\")\ndevtools::install_github(\"kassambara\/ggpubr\")<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Load ggpubr:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>library(\"ggpubr\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Related articles<\/h2>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/77-facilitating-exploratory-data-visualization-application-to-tcga-genomic-data\/\"> Facilitating Exploratory Data Visualization: Application to TCGA Genomic Data<\/a><\/p>\n\n\n\n<p>Description: Plot one or a list of variables at once.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Gene expression data<\/li><li>Box plots<\/li><li>Violin plots<\/li><li>Stripcharts and dot plots<\/li><li>Density plots<\/li><li>Histogram plots<\/li><li>Empirical cumulative density function<\/li><li>Quantile &#8211; Quantile plot<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/76-add-p-values-and-significance-levels-to-ggplots\/\"> Add P-values and Significance Levels to ggplots<\/a><\/p>\n\n\n\n<p>Description: Compute and add automatically p-values and significance levels to ggplots.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Methods for comparing means<\/li><li>R functions to add p-values\n<ul><li>compare_means()<\/li><li>stat_compare_means()<\/li><\/ul><\/li><li>Compare two independent groups<\/li><li>Compare two paired samples<\/li><li>Compare more than two groups<\/li><li>Multiple grouping variables<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/78-perfect-scatter-plots-with-correlation-and-marginal-histograms\/\"> Perfect Scatter Plots with Correlation and Marginal Histograms<\/a><\/p>\n\n\n\n<p>Description: Create beautiful scatter plots with correlation coefficients and marginal histograms\/density.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Basic plots<\/li><li>Color by groups<\/li><li>Add concentration ellipses<\/li><li>Add point labels<\/li><li>Bubble chart<\/li><li>Color by a continuous variable<\/li><li>Add marginal plots<\/li><li>Add 2d density estimation<\/li><li>Application to gene expression data<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/79-plot-meansmedians-and-error-bars\/\"> Plot Means\/Medians and Error Bars<\/a><\/p>\n\n\n\n<p>Description: Plot easily means or medians with error bars.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Error plots<\/li><li>Line plots<\/li><li>Bar plots<\/li><li>Add labels<\/li><li>Application to gene expression data<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/80-bar-plots-and-modern-alternatives\/\"> Bar Plots and Modern Alternatives<\/a><\/p>\n\n\n\n<p>Description: Create easily basic and ordered bar plots, as well as, \nsome modern alternatives to bar plots, including lollipop charts and \ncleveland\u2019s dot plots.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Basic bar plots<\/li><li>Multiple grouping variables<\/li><li>Ordered bar plots<\/li><li>Deviation graphs<\/li><li>Alternatives to bar plots\n<ul><li>Lollipop chart<\/li><li>Cleveland\u2019s dot plot<\/li><\/ul><\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/84-add-text-labels-to-histogram-and-density-plots\/\"> Add Text Labels to Histogram and Density Plots<\/a><\/p>\n\n\n\n<p>Description: Create histograms\/density plots and highlight some key elements on the plot.<\/p>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/81-ggplot2-easy-way-to-mix-multiple-graphs-on-the-same-page\/\"> ggplot2 &#8211; Easy Way to Mix Multiple Graphs on The Same Page<\/a><\/p>\n\n\n\n<p>Description: Step by step guide to combine multiple ggplots on the same page, as well as, over multiple pages.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create some plots<\/li><li>Arrange on one page<\/li><li>Annotate the arranged figure<\/li><li>Align plot panels<\/li><li>Change column\/row span of a plot<\/li><li>Use common legend for combined ggplots<\/li><li>Scatter plot with marginal density plots<\/li><li>Mix table, text and ggplot2 graphs<\/li><li>Insert a graphical element inside a ggplot\n<ul><li>Place a table within a ggplot<\/li><li>Place a box plot within a ggplot<\/li><li>Add background image to ggplot2 graphs<\/li><\/ul><\/li><li>Arrange over multiple pages<\/li><li>Nested layout with ggarrange()<\/li><li>Export plots<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/82-ggplot2-easy-way-to-change-graphical-parameters\/\"> ggplot2 &#8211; Easy Way to Change Graphical Parameters<\/a><\/p>\n\n\n\n<p>Description: Describe the function ggpar() [in ggpubr], which can be \nused to simply and easily customize any ggplot2-based graphs.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Change titles and axis labels<\/li><li>Change legend position &amp; appearance<\/li><li>Change color palettes\n<ul><li>Group colors<\/li><li>Gradient colors<\/li><\/ul><\/li><li>Change axis limits and scales<\/li><li>Customize axis text and ticks<\/li><li>Rotate a plot<\/li><li>Change themes<\/li><li>Remove ggplot components<\/li><\/ul>\n\n\n\n<p><a href=\"http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/83-create-and-customize-multi-panel-ggplots-easy-guide-to-facet\/\"> Create and Customize Multi-panel ggplots: Easy Guide to Facet<\/a><\/p>\n\n\n\n<p>Description: split up your data by one or more variables and to visualize the subsets of the data together.<\/p>\n\n\n\n<p>Contents:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Facet by one grouping variables<\/li><li>Facet by two grouping variables<\/li><li>Modifying panel label appearance<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Examples of plots created with ggpubr<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Distribution<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>library(ggpubr)\n# Create some data format\n# :::::::::::::::::::::::::::::::::::::::::::::::::::\nset.seed(1234)\nwdata = data.frame(\n   sex = factor(rep(c(\"F\", \"M\"), each=200)),\n   weight = c(rnorm(200, 55), rnorm(200, 58)))\nhead(wdata, 4)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>##   sex weight\n## 1   F   53.8\n## 2   F   55.3\n## 3   F   56.1\n## 4   F   52.7<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Density plot with mean lines and marginal rug\n# :::::::::::::::::::::::::::::::::::::::::::::::::::\n# Change outline and fill colors by groups (\"sex\")\n# Use custom palette\nggdensity(wdata, x = \"weight\",\n   add = \"mean\", rug = TRUE,\n   color = \"sex\", fill = \"sex\",\n   palette = c(\"#00AFBB\", \"#E7B800\"))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-distribution-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># Histogram plot with mean lines and marginal rug\n# :::::::::::::::::::::::::::::::::::::::::::::::::::\n# Change outline and fill colors by groups (\"sex\")\n# Use custom color palette\ngghistogram(wdata, x = \"weight\",\n   add = \"mean\", rug = TRUE,\n   color = \"sex\", fill = \"sex\",\n   palette = c(\"#00AFBB\", \"#E7B800\"))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-distribution-2.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Box plots and violin plots<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># Load data\ndata(\"ToothGrowth\")\ndf &lt;- ToothGrowth\nhead(df, 4)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>##    len supp dose\n## 1  4.2   VC  0.5\n## 2 11.5   VC  0.5\n## 3  7.3   VC  0.5\n## 4  5.8   VC  0.5<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># Box plots with jittered points\n# :::::::::::::::::::::::::::::::::::::::::::::::::::\n# Change outline colors by groups: dose\n# Use custom color palette\n# Add jitter points and change the shape by groups\n p &lt;- ggboxplot(df, x = \"dose\", y = \"len\",\n                color = \"dose\", palette =c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"),\n                add = \"jitter\", shape = \"dose\")\n p<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-box-plot-dot-plots-strip-charts-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code> # Add p-values comparing groups\n # Specify the comparisons you want\nmy_comparisons &lt;- list( c(\"0.5\", \"1\"), c(\"1\", \"2\"), c(\"0.5\", \"2\") )\np + stat_compare_means(comparisons = my_comparisons)+ # Add pairwise comparisons p-value\n  stat_compare_means(label.y = 50)                   # Add global p-value<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-box-plot-dot-plots-strip-charts-2.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code># Violin plots with box plots inside\n# :::::::::::::::::::::::::::::::::::::::::::::::::::\n# Change fill color by groups: dose\n# add boxplot with white fill color\nggviolin(df, x = \"dose\", y = \"len\", fill = \"dose\",\n         palette = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"),\n         add = \"boxplot\", add.params = list(fill = \"white\"))+\n  stat_compare_means(comparisons = my_comparisons, label = \"p.signif\")+ # Add significance levels\n  stat_compare_means(label.y = 50)                                      # Add global the p-value <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-box-plot-dot-plots-strip-charts-3.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Bar plots<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Demo data set<\/h4>\n\n\n\n<p>Load and prepare data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Load data\ndata(\"mtcars\")\ndfm &lt;- mtcars\n# Convert the cyl variable to a factor\ndfm$cyl &lt;- as.factor(dfm$cyl)\n# Add the name colums\ndfm$name &lt;- rownames(dfm)\n# Inspect the data\nhead(dfm[, c(\"name\", \"wt\", \"mpg\", \"cyl\")])<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>##                                name   wt  mpg cyl\n## Mazda RX4                 Mazda RX4 2.62 21.0   6\n## Mazda RX4 Wag         Mazda RX4 Wag 2.88 21.0   6\n## Datsun 710               Datsun 710 2.32 22.8   4\n## Hornet 4 Drive       Hornet 4 Drive 3.21 21.4   6\n## Hornet Sportabout Hornet Sportabout 3.44 18.7   8\n## Valiant                     Valiant 3.46 18.1   6<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Ordered bar plots<\/h4>\n\n\n\n<p>Change the fill color by the grouping variable \u201ccyl\u201d. Sorting will be done globally, but not by groups.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggbarplot(dfm, x = \"name\", y = \"mpg\",\n          fill = \"cyl\",               # change fill color by cyl\n          color = \"white\",            # Set bar border colors to white\n          palette = \"jco\",            # jco journal color palett. see ?ggpar\n          sort.val = \"desc\",          # Sort the value in dscending order\n          sort.by.groups = FALSE,     # Don't sort inside each group\n          x.text.angle = 90           # Rotate vertically x axis texts\n          )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-ordered-bar-plots-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Sort bars inside each group. Use the argument <strong>sort.by.groups = TRUE<\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggbarplot(dfm, x = \"name\", y = \"mpg\",\n          fill = \"cyl\",               # change fill color by cyl\n          color = \"white\",            # Set bar border colors to white\n          palette = \"jco\",            # jco journal color palett. see ?ggpar\n          sort.val = \"asc\",           # Sort the value in dscending order\n          sort.by.groups = TRUE,      # Sort inside each group\n          x.text.angle = 90           # Rotate vertically x axis texts\n          )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-ordered-bar-plots-by-groups-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Deviation graphs<\/h4>\n\n\n\n<p>The deviation graph shows the deviation of quantitative values to a \nreference value. In the R code below, we\u2019ll plot the mpg z-score from \nthe mtcars dataset.<\/p>\n\n\n\n<p>Calculate the z-score of the mpg data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Calculate the z-score of the mpg data\ndfm$mpg_z &lt;- (dfm$mpg -mean(dfm$mpg))\/sd(dfm$mpg)\ndfm$mpg_grp &lt;- factor(ifelse(dfm$mpg_z &lt; 0, \"low\", \"high\"), \n                     levels = c(\"low\", \"high\"))\n# Inspect the data\nhead(dfm[, c(\"name\", \"wt\", \"mpg\", \"mpg_z\", \"mpg_grp\", \"cyl\")])<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>##                                name   wt  mpg  mpg_z mpg_grp cyl\n## Mazda RX4                 Mazda RX4 2.62 21.0  0.151    high   6\n## Mazda RX4 Wag         Mazda RX4 Wag 2.88 21.0  0.151    high   6\n## Datsun 710               Datsun 710 2.32 22.8  0.450    high   4\n## Hornet 4 Drive       Hornet 4 Drive 3.21 21.4  0.217    high   6\n## Hornet Sportabout Hornet Sportabout 3.44 18.7 -0.231     low   8\n## Valiant                     Valiant 3.46 18.1 -0.330     low   6<\/code><\/pre>\n\n\n\n<p>Create an ordered bar plot, colored according to the level of mpg:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggbarplot(dfm, x = \"name\", y = \"mpg_z\",\n          fill = \"mpg_grp\",           # change fill color by mpg_level\n          color = \"white\",            # Set bar border colors to white\n          palette = \"jco\",            # jco journal color palett. see ?ggpar\n          sort.val = \"asc\",           # Sort the value in ascending order\n          sort.by.groups = FALSE,     # Don't sort inside each group\n          x.text.angle = 90,          # Rotate vertically x axis texts\n          ylab = \"MPG z-score\",\n          xlab = FALSE,\n          legend.title = \"MPG Group\"\n          )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-deviation-graphs-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Rotate the plot: use rotate = TRUE and sort.val = \u201cdesc\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggbarplot(dfm, x = \"name\", y = \"mpg_z\",\n          fill = \"mpg_grp\",           # change fill color by mpg_level\n          color = \"white\",            # Set bar border colors to white\n          palette = \"jco\",            # jco journal color palett. see ?ggpar\n          sort.val = \"desc\",          # Sort the value in descending order\n          sort.by.groups = FALSE,     # Don't sort inside each group\n          x.text.angle = 90,          # Rotate vertically x axis texts\n          ylab = \"MPG z-score\",\n          legend.title = \"MPG Group\",\n          rotate = TRUE,\n          ggtheme = theme_minimal()\n          )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-deviation-graphs-horizontal-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Dot charts<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Lollipop chart<\/h4>\n\n\n\n<p>Lollipop chart is an alternative to bar plots, when you have a large set of values to visualize.<\/p>\n\n\n\n<p>Lollipop chart colored by the grouping variable \u201ccyl\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggdotchart(dfm, x = \"name\", y = \"mpg\",\n           color = \"cyl\",                                # Color by groups\n           palette = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"), # Custom color palette\n           sorting = \"ascending\",                        # Sort value in descending order\n           add = \"segments\",                             # Add segments from y = 0 to dots\n           ggtheme = theme_pubr()                        # ggplot2 theme\n           )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-lollipop-chart-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Sort in descending order. <strong>sorting = \u201cdescending\u201d<\/strong>.<\/li><li>Rotate the plot vertically, using <strong>rotate = TRUE<\/strong>.<\/li><li>Sort the mpg value inside each group by using <strong>group = \u201ccyl\u201d<\/strong>.<\/li><li>Set <strong>dot.size<\/strong> to 6.<\/li><li>Add mpg values as label. <strong>label = \u201cmpg\u201d<\/strong> or <strong>label = round(dfm$mpg)<\/strong>.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ggdotchart(dfm, x = \"name\", y = \"mpg\",\n           color = \"cyl\",                                # Color by groups\n           palette = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"), # Custom color palette\n           sorting = \"descending\",                       # Sort value in descending order\n           add = \"segments\",                             # Add segments from y = 0 to dots\n           rotate = TRUE,                                # Rotate vertically\n           group = \"cyl\",                                # Order by groups\n           dot.size = 6,                                 # Large dot size\n           label = round(dfm$mpg),                        # Add mpg values as dot labels\n           font.label = list(color = \"white\", size = 9, \n                             vjust = 0.5),               # Adjust label parameters\n           ggtheme = theme_pubr()                        # ggplot2 theme\n           )<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-lollipop-chart-rotate-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>Deviation graph:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Use y = \u201cmpg_z\u201d<\/li><li>Change segment color and size: add.params = list(color = \u201clightgray\u201d, size = 2)<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ggdotchart(dfm, x = \"name\", y = \"mpg_z\",\n           color = \"cyl\",                                # Color by groups\n           palette = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"), # Custom color palette\n           sorting = \"descending\",                       # Sort value in descending order\n           add = \"segments\",                             # Add segments from y = 0 to dots\n           add.params = list(color = \"lightgray\", size = 2), # Change segment color and size\n           group = \"cyl\",                                # Order by groups\n           dot.size = 6,                                 # Large dot size\n           label = round(dfm$mpg_z,1),                        # Add mpg values as dot labels\n           font.label = list(color = \"white\", size = 9, \n                             vjust = 0.5),               # Adjust label parameters\n           ggtheme = theme_pubr()                        # ggplot2 theme\n           )+\n  geom_hline(yintercept = 0, linetype = 2, color = \"lightgray\")<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-lollipop-chart-deviation-1.png\" alt=\"\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Cleveland\u2019s dot plot<\/h4>\n\n\n\n<p>Color y text by groups. Use y.text.col = TRUE.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ggdotchart(dfm, x = \"name\", y = \"mpg\",\n           color = \"cyl\",                                # Color by groups\n           palette = c(\"#00AFBB\", \"#E7B800\", \"#FC4E07\"), # Custom color palette\n           sorting = \"descending\",                       # Sort value in descending order\n           rotate = TRUE,                                # Rotate vertically\n           dot.size = 2,                                 # Large dot size\n           y.text.col = TRUE,                            # Color y text by groups\n           ggtheme = theme_pubr()                        # ggplot2 theme\n           )+\n  theme_cleveland()                                      # Add dashed grids<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/www.sthda.com\/english\/sthda-upload\/figures\/ggpubr\/004-ggpubr-overview-cleveland-dot-plots-1.png\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/www.sthda.com\/english\/articles\/24-ggpubr-publication-ready-plots\/ The ggpubr R package facilitates the creation of beautiful ggplot2-based graphs for researcher with non-advanced programming backgrounds. The current material starts by presenting a&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1120","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/1120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=1120"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/1120\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=1120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=1120"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=1120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}