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.
Related
I am using a package called microbiomeMarker to plot a cladogram (ggtree). It was taking too long to print so I implemented the Cairo package so that the printing is faster (there's a considerable change thankfully.
cladogram<-plot_cladogram(
OTU_lefse_res,
color = c("#7570B3","#D95F02"),
only_marker = TRUE,
branch_size = 0.2, #beyond this point everything is default values
alpha = 0.2,
node_size_scale = 1,
node_size_offset = 1,
clade_label_level = 4,
clade_label_font_size = 4,
annotation_shape = 22,
annotation_shape_size = 5,
group_legend_param = list(),
marker_legend_param = list()
)
ggsave(
filename = "16S_Marker_Cladogram.png",
units = "px",
dpi = 300,
type = "cairo-png"
)
My issue is that when it gets saved, the graph is zoomed in (as far as I can figure to the bottom right corner of the legend) so I can't see the cladogram. I've also tried saving it as a pdf, changing the dpi to 900, defining the size by pixels, setting in the ggplot "coord_fixed()"... I'm at a loss, I googled the issue but I can't find anyone having a similar issue. The example data of the package works fine. I've got about 10x the amount of data to be plotted, so I expect some delay, but I don't understand why I can't get it right.
If I don't set a printing device and just do:
plot_cladogram(
OTU_lefse_res,
color = c("#7570B3","#D95F02"),
only_marker = TRUE,
branch_size = 0.2,
alpha = 0.2,
node_size_scale = 1,
node_size_offset = 1,
clade_label_level = 4,
clade_label_font_size = 4,
annotation_shape = 22,
annotation_shape_size = 5,
group_legend_param = list(),
marker_legend_param = list()
)
I don't get any output in the plot window. Any ideas of something else I can try?
I am performing ESEM with psych.
esem.diagram returns a graph in which the items overlap.
I would like to ask for some help with fixing the overlap or removing the rectangles please :)
My Code:
esem1 <- esem(modelESEM, varsX=c(1:33),varsY=c(34:41) ,nfX = 4, nfY = 1, fm = "minres",
rotate = "promax", plot = TRUE, cor = "cor", use = "pairwise")
esem.diagram(esem=esem1, cut=0.4)
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)
)
So, I am trying to create a pretty heatmap with pheatmap function in R.
I want to have coloured bars where the dendrogram stops and the graph starts in order to annotate the different clusters. Like a horizontal thick line running through columns and changes colours when it pass to another cluster. It's pretty common I think. But I can't figure out the 'annotations' in pheatmap. Any ideas?
structure<-matrix(rnorm(10000),ncol=100,nrow=100)
dist_structue<-dist(structure)
clustering<-hclust(dist)
cols2 = colorRampPalette(c('green','white','red'))(20)
annotation <- data.frame(Var1 = factor(cutree(clustering, k = 4))
heat_chem <- pheatmap(as.matrix(dist_structure),
clustering_distance_rows=dist_structure,
cellwidth = 4, cellheight = 4, cluster_rows=T,cluster_cols=T, legend = T,
clustering_distance_cols = dist_structure, show_rownames = TRUE,
fontsize_row = 5, annotation_row = annotation,
show_colnames = FALSE, cutree_cols = 4, cutree_rows=4,
color = cols2,
main = 'Heatmap')
The rownames of annotation are not matching the rownames of as.matrix(dist_structure)
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)