I have a mosaic, and I want to change the size of the character of the labels. What can I do?
library(vcd)
tbl<-structable(GWage~Gender,data=dat)
mosaic(tbl,shade=TRUE, legend=TRUE)
Updated for Mosaic()
mosaic(UCBAdmissions, sort = 3:1,
gp_varnames = gpar(fontsize = 14, fontface = 1),
gp_labels = gpar(fontsize = 10),
main = "Student admissions at UC Berkeley")
?labelings
See ?labelings & play around with the font sizes till you get what you want. You should probably post a tibble /mini-extract of your data to make it easily reproducible.
you may be able to do more with mosaicplot()?
Did you try
cex.axis = 0.7 # or whatever size works for your plot?
#Example:
table1 <- table(airquality$Temp[1:7], airquality$Month[1:7])
mosaicplot(table1,
main = "Example",
xlab = "Y",
ylab = "X",
las = 2,
border = "chocolate",
cex.axis = 0.7,
shade = TRUE)
Related
I'm trying to wrangle a Volcano plot made with the EnhancedVolcano package to have all text in Arial font style. I tried to do so with this code:
a <- EnhancedVolcano(data.matrix,
lab = rownames(data.matrix), x = "Log2.fold.change",
y = "P.value", xlim = c(-2, 2), ylim = c(0, 6), xlab = bquote(~ Log[2] ~ "fold change"),
ylab = bquote(~ -Log[10] ~ italic(P)), axisLabSize = 12,
title = paste("NanoString -", data.name), subtitle = "",
labFace = "bold", pointSize = 2, labSize = 5, pCutoff = 10e-2, FCcutoff = 0.4,
gridlines.major = FALSE, gridlines.minor = FALSE, drawConnectors = TRUE,
widthConnectors = 0.2, colConnectors = "black", legendPosition = "none"
)
print(a)
EV_merge <- a + theme(text = element_text(size = 8, family = "sans"))
print(EV_merge)
The problem I'm having is the element_text command, which I thought would work since the plot is an object in ggplot2, seems to only work for the axis and title text, but the font of the labels for the specific genes seems to remain the same. What function should I be using in this case?
The labels are nothing to do with theme. They are created by geom_text_repel, so they are part of a data layer. There doesn't seem to be an option to change the font family of the labels, but you can change it in situ after the plot is created.
Obviously, I don't have your data, but using the example from the help page and saving it as EV_merge, we have:
EV_merge
To change the font face and family, we can do:
EV_merge$layers[[4]]$aes_params$fontface <- 1
EV_merge$layers[[4]]$aes_params$family <- "sans"
EV_merge
Normally I provide some sample code for an reproducible example, but in this case it is a bit tricky. But I believe this question can be solved also without a reproduced example.
I have an image plot generated with the following code:
col <- c("red", "white", "blue") # set the color palette
image.plot(lon.list[[1]], lat.list[[1]], MK.list3[[6]][[8]],
main = paste0("Drought Index Trend \n", names(Index.list[[1]])[1]),
col = col,
xlab = "Longitude [°]",
ylab = "Latitude [°]",
legend.lab = "",
legend.line = 2.5,
zlim = c(-1,1))
plot(sf_object, add = T, border = "Black")
The resulting plot is the following:
I have a problem with the legend labels. Since there are only three values, -1, 0, 1, it is sufficient that only these values are displayed at the legend in the middle of each color.
So it should like this (the different colors don't matter):
Anybody with a hint how to achieve this?
Thanks to the comment of user20650, I found the solution. Here is the updated code which does what I want:
col <- c("red", "white", "blue") # set the color palette
image.plot(lon.list[[1]], lat.list[[1]], MK.list3[[6]][[8]],
main = names(Index.list[[1]])[8],
col = col,
xlab = "",
ylab = "",
legend.lab = "",
legend.line = 2.5,
zlim = c(-1,1),
axis.args = list(c(-1:1))) ### this is the new part ###
plot(sf_object, add = T, border = "Black")
I'm trying to get specific font sizes for scatterplots based of Nature guidelines. I'm told to keep all my point sizes for text at 7 so I've used par(ps = 7). However, I need a different font size for the main title. I need 8 point font size. I understand I can use cex.main but I'm so confused about the ratios to get that exact point size. Can someone tell me how to get exactly 8 point font size for the title.
Here is my code for one of the graphs:
par(mfrow=c(2,2), ps = 7)
par(mar=c(6,4,1,0))
#Plot for Confirmed Tick Data
plot(tick1_data$Year, tick1_data$average_cases,
main = "a",
cex.main = 1/1.14, ## I'm not sure this is giving me 8 point font size ##
type = "p",
pch = 19,
cex = 2,
col = '#BF0436',
xlab = "",
ylab = "Average Confirmed Cases",
ylim = c(0,308),
bty = "n",
xaxt = "n")
mtext(side = 1, text = "Year", line = 5)
par(bty = "n")
axis(side = 1, at = seq(2006, 2017, by = 1), las = 2)
rect(2004, -10, 2100, 50, border = NA, col = "#d3d3d365")
lines(spline(2005:2017, tick1_data$average_cases, n = 100), col= "#BF0436", lwd = 2)
Can anyone tell me how to set attributes within qqmath from the lattice package. Specifically how do I increase the font size of axis titles, axis text etc? None of the native plot arguments seem to work.
library(lattice)
lattice::qqmath(~ rnorm(100), distribution = function(p) qt(p, df = 10),
id=0.05,
main = "this is a title",
ylab = "this is a y-axis",
xlab = "this is an x-axis",
cex = 2,
cex.axis = 4,
font = 2,
cex.lab = 4)
Found a solution in the labyrinth that is the help page for lattice. In order to specify attributes of axis labels in lattice graphs you need to use the x and y argument within the scales argument, all wrapped in list(). To change the font size of titles you also need to wrap everything in a list():
lattice::qqmath(~ rnorm(100), distribution = function(p) qt(p, df = 10),
id=0.05,
main = list("this is a title", cex = 2),
ylab = list("this is a y-axis", cex = 3),
xlab = list("this is an x-axis", cex = 4),
scales = list(x = list(cex = 4)))
I'm using the VennDiagram R package to try to generate a neatly formatted diagram comparing two groups. I have successfully used this package in the past to compare relatively similarly-sized groups. However, now I'm comparing groups that have significantly different sizes (# of unique elements in the first group is ~3,600, # of unique elements in the second group is ~60, and # of overlapping elements is ~80).
The appearance of my current Venn diagram is that the group with the larger # of elements has this value displayed within its circle, but the labels for the intersection of the two groups and the unique elements in the second group are too large to be included in those regions of the diagram, so instead, they are displayed outside of the diagram with a line connecting them to the associated region. I don't like the appearance of this, and would like to reduce the size of all 3 labels so that they can be displayed within their respective regions of the diagram. However, after having reviewed the associated documentation/examples and publication (Chen & Boutros 2011), I'm still not clear about how to do this. (For example, I see parameters that permit the specification of font size of the figure title and subtitle, but I don't see where the labels' font size can be specified...)
I have attempted workarounds such as trying to make the labels invisible so that I can manually add them in a separate application, but this doesn't seem to be an option...
Any suggestions for how I can reduce the font size of my labels and specify that these labels appear within the regions of the diagram rather than outside of the diagram, will be appreciated. Thanks!
Update: As requested below, I am providing my example code:
library(VennDiagram);
library(grid);
Data <- read.csv('ExampleDataset_VennDiagram.csv')
Dataset1 <- Data[,1]
Dataset2 <- Data[,2]
MyVennDiagram <- venn.diagram(
x = list(
A = Dataset1,
B = Dataset2
),
main = "",
main.cex = NULL,
filename = NULL,
lwd = 2,
fill = c("blue", "green"),
alpha = 0.75,
label.col = "black",
cex=c(2,2,2),
fontfamily = "sansserif",
fontface = "bold",
cat.col = c("blue", "green"),
cat.cex = 0,
cat.fontfamily = "serif",
cat.fontface = "bold",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
);
grid.newpage()
grid.draw(MyVennDiagram)
Update: Based on missuse's suggestion below, using ext.text = FALSE works perfectly!
Thanks to everyone who contributed to this thread.
The eulerr library appears to generate nice-looking diagrams, and will definitely be a resource I use in the future -- thanks for sharing.
A possible solution to this is to avoid using euler diagrams.
To illustrate your problem here is some data:
A = sample(1:1000, 500, replace = T)
B = sample(1:10000, 50)
Here is the diagram obtained by
library(VennDiagram);
library(grid)
MyVennDiagram = venn.diagram(
x = list(
A = A,
B = B
),
main = "",
main.cex = NULL,
filename = NULL,
lwd = 2,
fill = c("cornflowerblue", "pink"),
alpha = 0.75,
label.col = "black",
cex=c(2,2,2),
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 0,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
)
grid.newpage()
grid.draw(MyVennDiagram)
by avoiding scaling of the circles with scaled = FALSE
MyVennDiagram = venn.diagram(
x = list(
A = A,
B = B
),
main = "",
main.cex = NULL,
filename = NULL,
lwd = 2,
fill = c("cornflowerblue", "pink"),
alpha = 0.75,
label.col = "black",
cex=c(2,2,2),
fontface = "plain",
cat.col = c("cornflowerblue", "pink"),
cat.cex = 0,
cat.fontfamily = "serif",
cat.fontface = "plain",
cat.dist = c(0.05, 0.05),
cat.pos = c(-20, 14),
cat.default.pos = "text",
scaled = FALSE
)
grid.newpage()
grid.draw(MyVennDiagram)
As per user20650 suggestion the best option is to use ext.text=FALSE in the original call:
Also check library(eulerr) it accepts a bit different input, here is an illustration:
library(eulerr)
library(tidyverse)
data.frame(dat = unique(c(A, B))) %>%
mutate(A = dat %in% A,
B = dat %in% B) %>%
select(A, B) %>%
euler() %>%
eulerr:::plot.euler(counts = T)
As per user20650 comment acceptable input is also:
plot(euler(setNames(list(unique(A),unique(B)), c("A", "B"))), counts=TRUE)