

#Rmarkdown text color plus
Graph with bold and colored headline text, plus legend removed. Let’s add tags to make the text bold, and let’s also add legend.position = none to remove the legend: my_chart + labs( title = "#python and #rstats: Comparing 1,000 random tweets" ) + theme( plot.title = element_markdown(), legend.position = "none" ) Sharon Machlis, IDG I find it a little hard to see the colors in this headline text, though. Ggplot2 graph with color in the headline text.
#Rmarkdown text color code
If you run all of the code until now, the graph should look like this: Sharon Machlis, IDG I did that in the above code inside a theme() function with plot.title = element_markdown(). In addition to adding my styling to the headline or other text, I need to add element_markdown() to whatever plot element has the colors. Note that there are two parts to styling text with ggtext.

my_chart #python and #rstats: Comparing 1,000 random tweets" ) + theme( plot.title = element_markdown() ) Next I’ll create a grouped bar chart and save it to the variable my_chart. That is typically the structure you want for most ggplot graphs. $ Category : chr "FiveLikes" "FiveRTs" "HasURL" "HasMedia".

$ Hashtag : chr "#python" "#python" "#python" "#python". The graph_data data frame is in a “long” format: one column for the hashtag (#rstats or #python), one for the category I’m measuring, and one column for the values. Or you could use any data set that makes sense as a grouped bar chart and modify my subsequent graph code accordingly. You can re-create the data set with the code block below. After downloading recent tweets, I did some filtering, took a random sample of 1,000 of each, and then calculated how many in each group had at least five likes, had at least five retweets, included a URL, and included media like a photo or video. remotes::install_github("tidyverse/ggplot2", build_vignettes = TRUE) remotes::install_github("wilkelab/ggtext", build_vignettes = TRUE) library(ggplot2) library(ggtext) library(dplyr)įor demo data, I’ll use data comparing tweets about R (with the #rstats hashtag) with tweets about Python (#python). After that, I load ggplot2, ggtext, and dplyr. Note that in the code below I include the argument build_vignettes = TRUE so I have local versions of package vignettes.
#Rmarkdown text color install
I use remotes::install_github() to install R packages from GitHub, although several other options, such as devtools::install_github(), work as well. The code above renders as shown below.You have to install ggtext from GitHub, since at the time I wrote this, the package wasn’t yet on CRAN. Note that the variable task-vectors (used in 3 positions above) needs to changed to a unique value for each such block in a document. If there is a character in a numeric vector, all elements are converted to characters (`typeof(x)`). In fact, all elements in this vector are characters.

X The third position is not a number, it's a character. If the accordion block is to contain regular text and code block, then the raw HTML code needs to be used.
