Unable to resize row labels in aheatmap - r

I am trying to create a heatmap using the aheatmap function from the NMF package. Below are the details of my data frame:
> dim(mirs)
[1] 249 10
> dput(head(mirs))
structure(list(Ctrl.1 = c(6.16181305031523, 7.1487208026042,
5.62305791288953, 6.48859753175019, 5.86448920099041, 7.54685590953394
), Ctrl.1 = c(6.01374431772049, 6.72364369422584, 5.94212799544158,
6.49697673701072, 6.27001491471232, 7.34423932678338), Ctrl.1 = c(6.08391877575544,
6.39383949993274, 5.9014256751437, 6.25322722017054, 6.02433921913527,
7.46048761260105), Ctrl.2 = c(6.05861842019582, 7.13778005751039,
6.07807310866636, 6.27799281508687, 5.9134130919514, 7.63249818573085
), Ctrl.3 = c(6.08966189744544, 7.50580543734962, 6.22308072664994,
6.50948356694844, 5.85467671344847, 7.69872387512424), KO.1 = c(6.01642055995834,
7.40800030898938, 5.76546680318882, 6.61403760055652, 5.94451005808497,
7.24179808413933), KO.1 = c(6.14954015244869, 7.35556286637155,
5.97997384889883, 6.63097271768056, 6.00315186944306, 7.4492860653164
), KO.1 = c(5.94805813320882, 6.84281163223775, 5.80410165075893,
6.34540217272193, 5.75166634057481, 7.47062580379961), KO.2 = c(5.97334370529652,
7.41685185578274, 6.09298712573127, 6.14896460752862, 6.03396383178639,
7.41543958735736), KO.3 = c(6.23339353310102, 7.8101475680467,
5.89241431063385, 6.35967585549527, 5.87334378152986, 7.62655831252478
)), .Names = c("Ctrl.1", "Ctrl.1", "Ctrl.1", "Ctrl.2", "Ctrl.3",
"KO.1", "KO.1", "KO.1", "KO.2", "KO.3"), row.names = c(24L, 29L,
243L, 290L, 309L, 499L), class = "data.frame")
> aheatmap(x = as.matrix(mirs), scale = 'row', distfun = dist2, legend = F, fontsize = 12, cexRow = .9, cexCol = .9, main = 'miRNA Expression Profile (n=249)', filename = 'plot.pdf', width = 5, height = 10)
There are 249 rows & 10 columns in my data but I have shown only top rows using head. The column labels resize accordingly when I change the fontsize but the problem is that the row labels do not. They appear really small in the pdf no matter how much I increase the fontsize or cexRow value. Can someone suggest how to increase the size of the row labels? Attached is my plot & as you can see I have used the same values for cexRow & cexCol but the rowlabels are really small compared to col labels.

There was indeed an issue in the computed fontsize for row labels.
This has now been fixed.
See: https://github.com/renozao/NMF/issues/38
The following should give you row labels that increase together with height:
aheatmap(x = as.matrix(dat), scale = 'row', legend = F
, main = 'Heatmap', filename = 'plot.pdf'
, width = 5, height = 10)

Related

How to adjust column width in dataframe of foretsplotter function

I am trying to create a forestplot, using forestplotter function, am able to get a beautiful graph, but am not able to see the entire graph, the column widths in few of the columns are so big, even if the string size is less, making the width of the entire graph, so big to see, can someone help me with this and also is it possible to align the datahrame contents uniformly centre aligned......Please help me with this
The code and relevant data are
###Required packages###
library(grid)
library(forestploter)
library(rmeta)
library(gridExtra)
#Data entered#
df <- data.frame(Study=c("A","B","C","D","Summary"),
nA = c(24,187,36,26,273),
median_A = c(4.9,5.69,8.866995074,8.5,NA),
Q1A =c(3,2.86,4.495073892,2,NA),
Q3A =c(8.5,9.78,14.96305419,32,NA),
nP = c(23,193,36,26,278),
median_P = c(7.2,6.79,8.990147783,12.5,NA),
Q1P =c(3.4,3.59,4.002463054,2,NA),
Q3P =c(10.9,10.12,12.06896552,43,NA),
W = c("10.6%","80.8%","8.0%","0.70%",NA),
E=c(-2.3,-1.1,-0.123152709,-4,-1.16881587),
UL=c(1.161473203,0.156288294,3.881699516,10.02689306,-0.039791047),
LL=c(-5.761473203,-2.356288294,-4.128004935,-18.02689306,-2.297840692))
#Calculate SE for box size#
df$SE <- (df$UL-df$E)/1.96
#Column for Confidence intervals for Drug A and Placebo, with 2 significant digit#
df$IQRA <- sprintf("%.2f (%.2f to %.2f)",df$median_A,df$Q1A, df$Q3A)
df$IQRP <- sprintf("%.2f (%.2f to %.2f)",df$median_P,df$Q1P, df$Q3P)
#Column for Confidence intervals for NET EFFECT, with 2 significant digit#
df$MD <- sprintf("%.2f (%.2f to %.2f)", df$E, df$LL, df$UL)
#Create a column with space for forest plot#
df$" "<- paste(rep(" ", 16), collapse = " ")
##Forest plot theme##
#To be modified as needed#
ftn <-forest_theme(
base_size = 16,
base_family = "serif",
ci_pch = 15,
ci_col = "black",
ci_lty = 1,
ci_lwd = 1,
ci_Theight = 0.25,
legend_name = " ",
legend_position = "right",legend_value = "",
xaxis_lwd = 1,
xaxis_cex = 0.7,
refline_lwd = 1,
refline_lty = "dashed",
refline_col = "red",
summary_fill = "blue",
summary_col = "blue",
footnote_cex = 0.4,
footnote_fontface = "plain",
footnote_col = "black",
title_just = c("center"),
title_cex = 1.1,
title_fontface = "bold",
title_col = "black",
show.rownames = FALSE)
##Table in Order for Forest plot##
#First get Column names#
colnames(df)
df2 <-df[,c(1,2,15,6,16,18,17)]
#Make NA cells empty
df2[5,3] <-c(" ")
df2[5,5] <-c(" ")
##Forestplot##
plot<-forest(df2,
est = df$E,
lower = df$LL,
upper = df$UL,
sizes = (df$SE/10),
ci_column = 6,
ref_line = 0,
arrow_lab = c("Drug A Better", "Placebo Better"),
xlim = c(-7, 6),
is_summary = c(FALSE,FALSE,FALSE,FALSE,TRUE),
xlog = FALSE,
ticks_digits = 0,ticks_at = c(-6,0,6),
theme = ftn)
##Show plot
print(plot, autofit = FALSE)

how to make calculation for y value in tooltip in sparkline in r

I am trying to show ranking in line and increase in number means a decrease in rank. That's why to visualize this relation I multiple rank values with minus 1. However, in tooltip it shows up with minus sign and I can't make calculations in double curly braces. Code is below.
library(data.table)
library(sparkline)
library(tidyverse)
library(DT)
vec_line <- data.table(rank = c(3,2,6,7), cur_year=c(2001,2002,2003,2004))
line = spk_chr(-vec_line[,rank],
type="line",
chartRangeMin = min(-vec_line[,rank]),
chartRangeMax = max(-vec_line[,rank]),
xvalues = vec_line[,cur_year],
tooltipFormat= sprintf('<span style=\"color: {{color}}\">●</span> Year {{x}}: {{y}}.'),
numberDigitGroupSep = "",
width = 150,
height = 50,
lineColor = '#896B84',
fillColor = NULL,
lineWidth = 2)
datatable(data.table(graph = line),
escape = F,
options = list(fnDrawCallback = htmlwidgets::JS('function(){HTMLWidgets.staticRender();}')))%>%
spk_add_deps()

Adjusting distance from labels to table in grid.arrange in R

I cannot find how to adjust distance from labels to table in grid.arrange:
distances_lsit = c(25,50,75,100)
category_lsit = 0:5
damage_table = matrix(NA, nrow=length(distances_lsit), ncol=length(category_lsit))
damage_table[1,] = c(10,25,50,75,100,100)
damage_table[2,] = c(5,10,25,50,75,100)
damage_table[3,] = c(2.5,5,10,25,50,75)
damage_table[4,] = c(0,2.5,5,10,25,50)
rownames(damage_table) = distances_lsit
colnames(damage_table) = category_lsit
table_scale = tableGrob(damage_table)
grid.arrange(table_scale, top = "Label 1", left = "Label 2")
which produces table as follows:
Is there anyway to glue it to the table? Thank you in advance for your help.
You should play with next parameters for finding your best location
heights;
widths;
textGrob.
For example, this:
grid.arrange(table_scale, top = textGrob("Really looks \n better now?", x = 0, hjust = -1), left = "I'm near,\n my man", heights = c(2,1), widths = c(1,1.5))
show to you this:

Add Space Between Panels of Openair windRose Plots

I created some windrose plots using the openair package and I'm pretty happy with how they turned out but aesthetically it would be nice to have some space between panels. Here's an example:
# windrose plot----
library(openair)
data("mydata")
windRose(mydata[1:144,], ws="ws", wd="wd",
paddle = F,
type = 'weekday',
key.header = 'Wind Speed (m/s)',
key.footer = "",
annotate = F,
angle = 30, # angle of "spokes"...sort of bins for wind direction
cols = 'jet',
key.position = 'right',
dig.lab = 2,
statistic = 'prop.count', #“prop.count” sizes bins according to the
# proportion of the frequency of measurements
fontsize = 20,
grid.line = 100,
max.freq = 105, # maximum value for the radial limits
key = list(header = "Wind Speed (m/s)",
footer = '',
labels = c('0 to 2', '2 to 4',
'4 to 6','6 or more'),
breaks = c(0,2,4,6)),
layout = c(6,1)
)
Anyone have any ideas of how to add space between the panels?
After some digging I found that this plot function utilizes trellis plots, here is a good rundown on them: https://www.stat.auckland.ac.nz/~ihaka/787/lectures-trellis.pdf
Specifically the xyplot function is used to create the trellis plot. The help documentation for ?xyplot shows that you can adjust the argument between to achieve spacing between panels. The between argument is a list containing x and y values that represent space between panels. Therefore we can adjust the above code simply by adding the argument between = list(x=0.25, y = 0.25) and can adjust x and y to our preference like this:
library(openair)
data("mydata")
windRose(mydata[1:144,], ws="ws", wd="wd",
paddle = F,
type = 'weekday',
key.header = 'Wind Speed (m/s)',
key.footer = "",
annotate = F,
angle = 30, # angle of "spokes"...sort of bins for wind direction
cols = 'jet',
key.position = 'right',
dig.lab = 2,
statistic = 'prop.count', #“prop.count” sizes bins according to the
# proportion of the frequency of measurements
fontsize = 20,
grid.line = 100,
max.freq = 105, # maximum value for the radial limits
key = list(header = "Wind Speed (m/s)",
footer = '',
labels = c('0 to 2', '2 to 4',
'4 to 6','6 or more'),
breaks = c(0,2,4,6)),
layout = c(6,1),
between = list(x=0.25, y=0.25)
)

R how to increase distance between grids when using plot function?

I'm learning the Numerical Ecology with R. However, I found all my plots lacking the distance between bars or grids.
myplot
textbook's plot
spe.KM.cascade <-
cascadeKM(
spe.norm2,
inf.gr = 2,
sup.gr = 10,
iter = 100,
criterion = "ssi"
)
dev.new(
title = "CascadeKM",
width = 10,
height = 6,
noRStudioGD = TRUE
)
plot(spe.KM.cascade, sortg = TRUE, border = 'white')
I want to know how to add white borders for every grid.

Resources