ggplot2 - italicize suffix of a plot label in R -


i have heatmap 1 label sting of 2 words separated ", ". italicize suffix of label while retaining unchanged font prefix. realize there questions addressing similar issues , apologize if repeated question i've been unable apply of solutions questions particular problem.

i have following code generates plot:

ggplot(mockdata, aes(variable, measurement)) +      geom_tile(aes(fill = mockdata$plotval), colour = "dark red")  + facet_grid(category~type, scales='free', space='free') + scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +      theme_minimal() + theme(axis.text.x=element_text(size=28, angle=90), axis.text.y=element_text(size=28)) +      labs(title="", x="", y="", fill="") + theme(strip.text.x=element_blank(),strip.text.y=element_text(size=20, angle=0)) 

enter image description here

i prefix (here number 23:42 string) remain unchanged whilst setting suffix in italics. how accomplish this? (i should note have columns prefix or suffix in dataframe expression(paste(column1, italics(column2), sep="")) work, although hasn't worked me far).

here reproducible data:

dput(mockdata) structure(list(measurement = structure(c(42l, 41l, 40l, 39l,  38l, 37l, 36l, 35l, 34l, 33l), .label = c("1, italic_suffix",  "2, italic_suffix", "3, italic_suffix", "4, italic_suffix", "5, italic_suffix",  "6, italic_suffix", "7, italic_suffix", "8, italic_suffix", "9, italic_suffix",  "10, italic_suffix", "11, italic_suffix", "12, italic_suffix",  "13, italic_suffix", "14, italic_suffix", "15, italic_suffix",  "16, italic_suffix", "17, italic_suffix", "18, italic_suffix",  "19, italic_suffix", "20, italic_suffix", "21, italic_suffix",  "22, italic_suffix", "23, italic_suffix", "24, italic_suffix",  "25, italic_suffix", "26, italic_suffix", "27, italic_suffix",  "28, italic_suffix", "29, italic_suffix", "30, italic_suffix",  "31, italic_suffix", "32, italic_suffix", "33, italic_suffix",  "34, italic_suffix", "35, italic_suffix", "36, italic_suffix",  "37, italic_suffix", "38, italic_suffix", "39, italic_suffix",  "40, italic_suffix", "41, italic_suffix", "42, italic_suffix" ), class = c("ordered", "factor")), category = structure(c(1l,  1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l), .label = c("x1", "x2", "x3",  "x4", "x5", "x6", "x7", "x8", "x9"), class = "factor"), variable = structure(c(1l,  1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l), .label = c("a", "b", "c",  "a", "b", "c", "d", "e", "f"), class = "factor"), pval = c(2.47889266743109e-11,  3.57296480818891e-12, 2.95428165629922e-21, 6.55646318564946e-12,  0.00140846156326513, 0.00504059407383829, 0.239272686561618,  0.146388841964746, 0.0193041667726786, 34.6978854862654), effect = c(1.40367296123877,  0.267565311381035, 0.157909806505032, 0.117848801449174, 0.139575361152878,  0.153551445281832, 0.254959981281264, 0.0635385821595322, 0.0832431045850506,  0.010863571087271), direction = c(1, 1, 1, 1, 1, 1, 1, 1, 1,  1), plotval = c(10.6057422771658, 11.4469712613471, 20.5295481021367,  11.1833303729987, 2.85125500035703, 2.29751827550182, 0.62110687410944,  0.83449202476544, 1.71434893912345, -1.54030300938373), type = structure(c(1l,  1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l), .label = c("individual",  "composite"), class = "factor"), `na` = list(c("rs188468174",  " runx3"), c("rs35668054", " cyp26b1"), c("rs968567", " fads2" ), c("rs9276244", " hla-dqa2"), c("rs10065637", " ankrd55"),      c("rs1071888", " ascc2"), c("rs142973694", " mica"), c("*rs3815768",      " ell2"), c("rs3184504", " sh2b3"), c("rs2926468", " fcgr3b"     )), `na` = c(" runx3", " cyp26b1", " fads2", " hla-dqa2",  " ankrd55", " ascc2", " mica", " ell2", " sh2b3", " fcgr3b")), .names = c("measurement",  "category", "variable", "pval", "effect", "direction", "plotval",  "type", na, na), row.names = c(na, 10l), class = "data.frame") 

here's how can use custom labels. idea taken from question linked haboryme. note minimised code bit since theme wasn't necessary demonstration purposes.

library(ggplot2) labs <- sapply(strsplit(as.character(mockdata$measurement), ", "),                 fun = function(x) {                  x1 <- x[1]; x2 <- x[2]                  parse(text = paste("plain('", x1, ",') ~ ", "italic('", x2, "')", sep = ""))                })  ggplot(mockdata, aes(variable, measurement)) +    geom_tile(aes(fill = mockdata$plotval), colour = "dark red")  +    facet_grid(category~type, scales='free', space='free') +    scale_fill_gradient2(limits=c(-20, 20),high = "firebrick3", low = "dodgerblue4") +    theme_minimal() +    scale_y_discrete(labels = labs, breaks = mockdata$measurement) +   labs(title="", x="", y="", fill="") 

enter image description here


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -