r hyphen in label of x axis - r

The x axis label has hyphen. This is not what I wrote in my code:
temp = table(res$Methode, res$Bewertung)
tempf = ftable(res$Methode, res$Bewertung)
barplot(tempf , xlab="Bewertung", ylab="absolute Häufigkeit", cex.lab = 1.4, beside=TRUE, ylim = c(0,600), xlim=c(11.75,1.7), col = colour2)
legend("top", legend=c("ohne LOD", "mit LOD"), horiz = TRUE, inset = c(0, 0), fill = rev(colour2), cex=1.4)
axis(1, at=c(11, 8, 5, 2),labels=c("sehr relevant", "mit­tel­mä­ßig relevant", "wenig relevant", "nicht relevant"), cex.axis=1.4)
How can I solve this?

Related

change second y axis color in base R

Change secondary line axis color changes send color for ggplot, but I chose to go with base R, and would like to be able to select the second y axis color.
I have the following data:
df = structure(list(A = c("Q4-17", "Q1-18", "Q2-18", "Q3-18", "Q4-18",
"Q1-19", "Q2-19", "Q3-19", "Q4-19", "Q1-20", "Q2-20", "Q3-20",
"Q4-20", "Q1-21", "Q2-21", "Q3-21", "Q4-21", "Q1-22", "Q2-22",
"Q3-22"), B = c(69.45, 71.1, 74.94, 73.87, 93.61, 91.83,
95.38, 109.8, 133.75, 125.26, 118.22, 145.65, 144.9757185, 155.3464032,
184.367033, 179.8121721, 187.235487, 189.1684376, 184.3864519,
161.5300056), C = c(70.73, 71.73, 74.33, 73.27,
95.94, 94.38, 95.38, 109.8, 115.32, 116.92, 115.9, 113.87, 106.108147,
96.84273563, 111.5150869, 110.1228567, 110.7448835, 194.9684376,
187.7241152, 167.7665553), D = c(260.3, 216.02, 203.72,
203.52, 300.96, 320.77, 330.5, 413.52, 436.7, 474.96, 463.6,
501.87, 493.8865461, 497.1760767, 514.9903459, 503.7601267, 510.8362938,
614.9915546, 603.5761107, 593.660831), E = c(NA,
NA, NA, NA, NA, NA, NA, NA, 39.237, 35.621, 32.964, NA, 152.137,
140.743023, 167.809, 170.877, 117.517, 102.691723, 88.8, 76.2445528
)), class = "data.frame", row.names = c(NA, -20L))
df = df %>%
rowwise() %>%
mutate(sums = sum(D,E, na.rm = TRUE))
df = df[8:nrow(df),]
and this to generate my plot
x <- seq(1,nrow(df),1)
y1 <- df$B
y2 <- df$D
par(mar = c(5, 4, 4, 4) + 0.3)
plot(x, y1, col = "#000000",
type = "l",
main = "title",
ylim = c(0, max(df[,2:3])),
ylab = "Y1",
xlab = "",
xaxt = "n")
axis(1,
at = seq(from = 13, by = -4, length.out = 4),
labels = df$A[seq(from = 13, by = -4, length.out = 4)])
lines(x, df$C, lty = "dashed", col = "#adadad", lwd = 2)
par(new = TRUE)
plot(x, df$sums, col = "#ffa500",
axes = FALSE, xlab = "", ylab = "", type = "l")
axis(side = 4, at = pretty(range(y2)),
ylim = c(0,max(df[,3:5], na.rm = TRUE)),
col = "#00aa00") # Add colour selection of 2nd axis
par(new = TRUE)
plot(x, df$D , col = "#0000ff",
axes = FALSE, xlab = "", ylab = "", type = "l", lwd = 1)
mtext("y2", side = 4, line = 3)
but this does not colour my complete second y axis, nor labels, nor title
does any one have any suggestions to be able to set entire y2 axis to be #00AA00 - ticks, labels, and title?

How can I adjust the legend box?

This is my code:
score <- tapply(exams$writing.score
, list(exams$gender,
exams$race.ethnicity
)
, mean)
plot1 <- barplot(score
, beside = TRUE
, main = "Comparison of Writing Score"
, col = c("red", "lightyellow")
, xlab = "Race Ethnicity Group"
, ylab = "Average Writing Score"
, legend.text = c("Female", "Male")
, args.legend = list(x = "topright")
)
As I want to make the box: Female and Male smaller so it does not hide the bar behind. How can I make the legend box smaller? I tried to move it to the top right of the chart, but I do not think it moves.
You could use the argument cex. Here is a reproducible example:
data <- matrix(c(1,2,3,4,5,6,7,8,9,10), ncol = 5)
colnames(data) <- paste0("V", 1:5)
rownames(data) <- c('A','B')
# Normal
barplot(data, col = 1:nrow(data))
legend("topright", legend = rownames(data), pch = 15, col = 1:nrow(data))
# With cex
barplot(data, col = 1:nrow(data))
legend("topright", legend = rownames(data), pch = 15, col = 1:nrow(data), cex = 0.5)
Created on 2022-10-21 with reprex v2.0.2
Another option (in addition to using cex as #Quinten shows) is to also change the inset to move the legend outside of the plot boundary, as well as using par to specify the parameters for margins, etc.
par(mar = c(5, 4, 4, 8),
xpd = TRUE)
# Normal
barplot(df, col = 1:nrow(df))
legend(
"topright",
inset = c(-0.1, 0),
# Create legend outside of plot
legend = rownames(df),
pch = 15,
col = 1:nrow(df),
cex = 0.8
)
Data
df <- structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), dim = c(2L, 5L), dimnames = list(
c("Female", "Male"), c("V1", "V2", "V3", "V4", "V5")))
It doesn't move because you already are at the very top. To move the top upwards and let the legend follow, expand ylim.
Also try if you like setting the legend horizontal and remove the bty (boxtype). Don't choose the cex too small.
barplot(score
, beside=TRUE
, main="Comparison of Writing Score"
, col=c("red", "lightyellow")
, xlab="Race Ethnicity Group"
, ylab="Average Writing Score"
, legend.text=c("Female", "Male")
, args.legend=list(x="topright", cex=.9, horiz=TRUE, bty='n')
, ylim=c(0, max(score)*1.2)
)
Data:
score <- structure(c(96.8, 95.2, 100, 100, 89.7, 89.2, 81.4, 81, 85.1,
82), dim = c(2L, 5L), dimnames = list(c("1", "2"), c("A", "B",
"C", "D", "E")))

Move hazard ratio values (and confidence intervals) left in forest() in metafor package

I am just trying to move the hazard ratio/outcome column with its corresponding CI values to the left so that I can add a p-value to the right of the outcomes column, Is this possible?
Is there an easy way to find this argument and others like it in the R documentation for forest()?
#Forest Plot
label1 <- as.character(c("<50", "50 to <60", "60"))
label1 <- factor(label1, levels = unique(label1))
hazards1 <- c(1.42, 1.66, 2.85)
lower1 <- c(1.34, 1.50, 2.59)
upper1 <- c(1.51, 1.85, 3.13)
patient_num1 <- c(240000, 180000, 220000)
event_num1 <- c(2600, 1300, 2900)
forestplot1 <- data.frame(label1, hazards1, lower1, upper1, event_num1, patient_num1)
forestplot1$patient_num1 <- rev(forestplot1$patient_num1)
par(mar=c(4,4,1,2))
pdf(file = "figureex.pdf", width = 15, height = 8.5)
pdf.options(encoding='ISOLatin2.enc')
forest(rev(hazards1), ci.lb = rev(lower1), ci.ub = rev(upper1), slab = rev(label1), xlim = c(-4,0),
xlab = "Adjusted Hazard Ratio for Event",
refline = 1, annotate = T, ylim = c(-1, 29), ilab = cbind(forestplot1$patient_num1, rev(event_num1)),
ilab.xpos=c(-1,-0.25), at = c(0.25, 0.5, 1, 2, 4, 6), rows = c(1:3),
cex = 1, yaxs = "i")
text(-4, 27.29, pos = 4, "Variable")
text(-1.25, 27.67, pos = 4, "No. of \nPatients")
text(-0.45, 27.67, pos = 4, "No. of \nEvents")
text(5.05, 27.69, pos = 4, "Hazard Ratio \n(95% CI)")
dev.off()

What pars to eliminate margin in a `png file` for the following R plot?

I was wondering given the R code for the plot below, how I can get a png file of this plot such that the plot fills all the image with no margin left?
What I have tried so far was playing with mar and oma with no success:
N = 20 ; df = N-1
par(oma = rep(0, 4), mar = rep(0, 4))
png("plot.png", width = 4, height = 5, units = "in", res = 500)
BB = curve( dt(x*sqrt(N), df)*sqrt(N), -1, 1, n = 1e4, xlab = "d",
ylab = NA, font = 2, font.lab = 2, type = "n", yaxt = "n", bty = "n", mgp = c(2, 1, -.5))
polygon(BB, col = rgb(1, 0, 0, .4), border = NA)
dev.off()
Finally, the following worked for me with the help of one of the colleagues from SO:
N = 20 ; df = N-1
par(oma = rep(0, 4), mar = c(2.5, .01, 0, .01), mgp = c(1.5, .3, 0), xpd = NA)
BB = curve( dt(x*sqrt(N), df)*sqrt(N), -1, 1, n = 1e4, xlab = "d",
ylab = NA, font = 2, font.lab = 4, type = "n", yaxt = "n",
bty = "n", cex.axis = .7, cex.lab = .9)
polygon(BB, col = rgb(1, 0, 0, .4), border = NA)
dev.copy(png, "plot.png", width = 2, height = 3, units = "in", res = 500)
dev.off()
dev.off()

How to assign name to every circle in a Venn diagram using R (Venndiagram package)

I would assign a name for every circle in a Venn diagram. I have tried to change options in category but seems this is the only set I can use. I attach my code, please where is the wrong part?
goterm3 = c(1,2,3,4,5,6)
goterm2 =c(2,2,3,4,3,5)
goterm1=c(4,5,3,2,4,3,2,4)
int12 = intersect(goterm1, goterm2)
int13 = intersect(goterm1, goterm3)
int23 = intersect(goterm2, goterm3)
intall = intersect(int12, goterm3)
require(VennDiagram)
venn.plot = draw.triple.venn(length(goterm1), length(goterm2), length(goterm3),
length(int12), length(int23), length(int13),length(intall),
category = rep("ORG1, ORG2,Org",3) ,rotation = 1, reverse = FALSE, euler.d = FALSE,
scaled = FALSE, lwd = rep(2, 3), lty = rep("solid", 3),
col = rep("black", 3), fill = c("blue", "red", "green"),
alpha = rep(0.5, 3),
label.col = rep("black", 7), cex = rep(1, 7), fontface = rep("plain", 7),
fontfamily = rep("serif", 7), cat.pos = c(0, 0, 180),
cat.dist = c(0.05, 0.05, 0.025), cat.col = rep("black", 3),
cat.cex = rep(1, 3), cat.fontface = rep("plain", 3),
cat.fontfamily = rep("serif", 3),
cat.just = list(c(0.5, 1), c(0.5, 1), c(0.5, 0)), cat.default.pos = "outer",
cat.prompts = FALSE, rotation.degree = 0, rotation.centre = c(0.5, 0.5),
ind = TRUE, sep.dist = 0.05, offset = 0)
This is what I get and it does have the same labels as your categories (after I unmangled the string values for the categories:
category = c("ORG1", "ORG2","Org") # no rep needed and proper quotes

Resources