I thought this should be easy but I've been having a hard time trying to modify the title of each plot. I'm just new to R so I really don't know how to edit this.
As you can see in the image, all the plot labels are centered but not properly placed. Some letters were cut out of the frame. These labels are automatically generated by ggdensity() when I combine 2 columns in one plot.
bell_shape <- lapply(slash_k, function(x) ggdensity(x, c("Mean_Lesion_Height", "Mean_Max_Lesion_Length"),
combine = TRUE,
add = "mean",
fill = "lightblue",
x.text.angle = 360,
color = "darkblue"))
pen_bell_shape <- ggarrange(plotlist = bell_shape,
widths = 10,
heights = 10,
nrow = 2,
ncol = 3,
labels = c("3.IR20", "5.IR20", "7.IR20", "3.TN1", "5.TN1", "7.TN1"),
font.label = list(size = 9, color = "red"))
I really have no idea how to edit this. I hope someone can help me.
I tried
bell_shape + theme(axis.title.x.top = c(size = 1, color ="block")
But it returns NULL
The solution to this problem is using
theme(strip.text())
This question has already been answered here:
[https://stackoverflow.com/questions/3290330/facet-label-font-size]
[https://stackoverflow.com/questions/2751065/how-can-i-manipulate-the-strip-text-of-facet-grid-plots]
[https://stackoverflow.com/questions/2631780/r-ggplot2-can-i-set-the-plot-title-to-wrap-around-and-shrink-the-text-to-fit-t]
This is also a good alternative
[https://stackoverflow.com/questions/2631780/r-ggplot2-can-i-set-the-plot-title-to-wrap-around-and-shrink-the-text-to-fit-t]
This can also provide insghts
[https://stackoverflow.com/questions/37089052/r-ggplot2-facet-grid-how-include-math-expressions-in-few-not-all-labels]
And here is how to change the facet labels
[https://stackoverflow.com/questions/3472980/how-to-change-facet-labels]
Documentation here
[https://rpkgs.datanovia.com/ggpubr/reference/facet.html]
Related
I have the following code line:
plot(reducedDims(seLX_MET)$UMAP[shuffle, ], asp = 1, pch = 16, xlab = "UMAP-1", ylab = "UMAP-2",
col = alpha(c(1,2,3,4,5,6)[factor(colData(seLX_MET)$cell_type)][shuffle], alpha = .5))
it is plotting for slingshot object (library slingshot). Although this is a specific bioinformatics tool, I think the color choice should be something common in plotting functions.
The problem is, whenever I try to increase the numbers in col = alpha(c(1,2,3,4,5,6) from 6 to 12 => alpha(c(1,2,3,4,5,6, 7, 8, 9, 10, 11, 12) it repeats the colors on the plot.
But factor(colData(seLX_MET)$cell_type) has 12 levels.
The output of this piece
alpha(c(1,2,3,4,5,6)[factor(colData(seLX_MET)$cell_type)][shuffle], alpha = .5)
is a list of color codes for each point.
So, my questions are:
what is the first alpha in this case? (I think the second alpha is transparency)
How to avoid color duplication in this case?
Although I still did not understand the role of alpha in this function, I ended up using RColorBrewer which gave me decent colors:
plot(reducedDims(seLX_MET)$UMAP[shuffle, ], asp = 1, pch = 16, xlab = "UMAP-1", ylab = "UMAP-2",
col = alpha(brewer.pal(12,"Paired")[factor(colData(seLX_MET)$cell_type)][shuffle], alpha = .5))
I´m new to R. I cannot put a legend in a plot chart, there is someting wrong with my code, I´ve tried to put a legend on this plot. I did a hash to put some colors on my model, but now I can´t figure out how to put the correct legend on it. This is what I di:
myhash<-c(a="green",b="pink",c="blue",d="purple",e="orange",f="brown",g="yellow",
h="black",i="gray")
mycolor<-myhash[df$category]
plot(df$growth,df$tannin,col=mycolor,cex=1,pch=16,xlab="Crecimiento",ylab="Taninos", main = "Modelo lineal Taninos vs Crecimiento")
I tried to put the legend like this :
legend("topright",c(df$tannin),fill=c("green","pink","blue","purple","orange","brown","yellow",
"black","gray"))
Please let me know how can I fix it, Im very beginner in R. Also, I cannot use any library.
Thanks in advance.
The problem seems to be that there is no legend (the argument to function legend, not the function) to show as text beside the fill colors.
To use a named argument, legend = unique(names(mycolor)) solves the problem.
set.seed(2020)
df <- data.frame(category = rep(c("a","b", "c", "d"), 4),
growth = 1:16, tannin = cumsum(rnorm(16)))
myhash <- c(a = "green", b = "pink", c = "blue", d = "purple")
mycolor <- myhash[df$category]
plot(df$growth, df$tannin, col = mycolor, cex = 1, pch = 16,
xlab = "Crecimiento", ylab = "Taninos",
main = "Modelo lineal Taninos vs Crecimiento")
legend("topright", legend = unique(names(mycolor)), fill = mycolor)
I am creating a multi panel figure that includes a ComplexHeatmap object so I am using multi_panel_figure() instead of ggarrange().
I have tried to include an argument to set the labels manually as I do in ggarrange but it does not work.
ggarrange(...,
font.label = list(size = 14, color = "black", face = "bold", family = NULL))
Like this:
Figure2 = multi_panel_figure(width = 360, height = 180,
columns = 3, rows = 1,
font.label = list(size = 24))
Figure2 %<>% fill_panel(DE_HM, column = 1)
Figure2 %<>% fill_panel(DE_TM, column = 2:3)
save_multi_panel_figure(figure = Figure2,
filename = "Figure2.svg")
I am quite new using ggplot2 so I do not know very well how to control the text size proportions. In this case I would like to make the labels bigger as I need to make the figure large so other text in it can be read easily. Maybe I should generate my figure any other way?
Here is how the labels look like right now (panel B need to be large so text can be read in the treemap):
With trace(fill_panel, edit=T) change the function fill_panel() on line 124 from:
panel_label <- textGrob(label = label, x = 1, y = 0, just = label_just)
to:
panel_label <- text_grob(label = label, x = 1, y = 0, just = label_just, face = "bold", size = 14)
also use library(ggpubr) in order to make this work.
I am trying to make a bar graph in R, but I have a permanent recurring problem. The legend appears wrong and I can't fix it.
If anyone knows how to fix it, I will be very grateful. I attach a screenshot from R:
Thanks!
I'm not sure what the exact issue is here since you posted a picture instead of a reproducible example, but the following code will give you the plot you want:
dev.off()
par(mai = c(1, 1, 1, 2))
barplot(table(cuestionario$genero),
main = "genero",
col = c("blue", "pink"),
ylab = "Cantidad",
ylim = c(0, 400),
beside = TRUE,
legend.text = TRUE,
args.legend = list(x = 3, y = 300))
I have been working on Venn Diagrams in GNU R. I have tried using the packages venneuler and VennDiagram. I find that VennDiagram has a lot more granular control, but it seems to lack the documentation to fill in all the details. The closest I can find is this PPT file.
http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3041657/bin/1471-2105-12-35-S4.PPT which I found from the URL: http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3041657/
Here are my issues with using VennDiagram.
For the code
require(VennDiagram)
venn.diagram(list(B = 1:2000, A = 200:400),fill = c("yellow", "blue"),
alpha = c(0.8, 0.8), cex =1.5, cat.pos=0, cat.fontface = 4,
lty = 1, fontfamily =3, filename = "test001.jpeg");
(I had an image here, but since I am new I do not have rights to post the image. Please generate the image from the code above.)
I can make a subset (hence a circle within a circle). But I am not finding a way to do the following:
Make BC to show as the equal of B^C. No, a literal "B^C" does not work. I would think there is a way to relabel the sets in a different property, but I have not seen a way to do it.
To position the labels of B^C and A^C within the sets and not on the outside as currently shown. I tried cat.pos="inner" but that way not a valid property. I also tried cat.pos=c(0,0) in the hope that I could feed it as an X,Y where X & Y are from the center of the circle, but it did not produce any different results.
Thanks to DWin, here is the code to complete my diagram to the exercise.
Suppose that A ⊂ B. Show that Bc ⊂ Ac.
require(VennDiagram)
plot.new()
venn.plot <- venn.diagram(
x = list(B = 1:200, A = 20:40), category.names= expression(B, A),
fill = c("yellow", "blue"), alpha = c(0.8, 0.8), cex =1.5,
cat.pos=0, cat.dist=c(-.1, -.1), filename = NULL) ;
grid.draw(venn.plot); # grid graphic requires explicit print or draw operation
grid.text(expression(B^c),x=0.2,y=0.95)
grid.text(expression(A^c),x=0.16,y=0.95)
grid.text(expression(A^c),x=0.16,y=0.75)
Perhaps something like this:
venn.diagram(list(B = 1:200, A = 20:40), category.names= expression(B^c, A),
fill = c("yellow", "blue"), alpha = c(0.8, 0.8), cex =1.5, cat.pos=0,
cat.dist=c(.1, -.1), cat.fontface = 4,lty = 1, fontfamily =3,
filename = "test001.jpeg")
To get the labels inside the circles, supply 'cat.dist' with negative values. The trick is that the reference point is radial distance from the boundary at 12 o'clock rather than from the center. The documentation says that the category.names argument is interpreted with plotmath syntax. The superscript operation in plotmath is done with the "^" operator. I have here moved the A" inside while leaving the B^c outside to suggest that it is the area outside the B circle that is being labeled. (I also improved the plotting time by making the example smaller.) I tried drawing three labels but that does not seem to "part of the package".
Here's a way you can annotate with grid.text() on the screen device:
plot.new()
venn.plot <- venn.diagram(
x = list(B = 1:200, A = 20:40), category.names= expression(B^c, A),
fill = c("yellow", "blue"), alpha = c(0.8, 0.8), cex =1.5,
cat.pos=0, cat.dist=c(.05, -.1), filename = NULL) ;
grid.draw(venn.plot); # grid graphic requires explicit print or draw operation
grid.text("B",x=0.8)
# then you can save to file