Forestplot R - expanding plot, edit a variable name
I prepared a code to visualize my data:
library(forestplot)
test_data <- data.frame(coef=c(1.14, 0.31, 10.70),
low=c(1.01, 0.12, 1.14),
high=c(1.30, 0.83, 100.16),
boxsize=c(0.2, 0.2, 0.2))
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
test_data <- rbind(rep(NA, 4), test_data)
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1,
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
It gives a following forestplot:
I would like to:
1) expand the plot and diminish font of the plot details on the left for better visualization
2) edit "So looooooong and nasty name of the variable" to move part "name..." below the row like:
"
So looooooong and nasty
name of the variable
"
However, when I write as "/nSo.../n" it gives another row of number from columns "OR" and "CIs".
How correct it?
r data-visualization forestplot
add a comment |
I prepared a code to visualize my data:
library(forestplot)
test_data <- data.frame(coef=c(1.14, 0.31, 10.70),
low=c(1.01, 0.12, 1.14),
high=c(1.30, 0.83, 100.16),
boxsize=c(0.2, 0.2, 0.2))
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
test_data <- rbind(rep(NA, 4), test_data)
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1,
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
It gives a following forestplot:
I would like to:
1) expand the plot and diminish font of the plot details on the left for better visualization
2) edit "So looooooong and nasty name of the variable" to move part "name..." below the row like:
"
So looooooong and nasty
name of the variable
"
However, when I write as "/nSo.../n" it gives another row of number from columns "OR" and "CIs".
How correct it?
r data-visualization forestplot
add a comment |
I prepared a code to visualize my data:
library(forestplot)
test_data <- data.frame(coef=c(1.14, 0.31, 10.70),
low=c(1.01, 0.12, 1.14),
high=c(1.30, 0.83, 100.16),
boxsize=c(0.2, 0.2, 0.2))
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
test_data <- rbind(rep(NA, 4), test_data)
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1,
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
It gives a following forestplot:
I would like to:
1) expand the plot and diminish font of the plot details on the left for better visualization
2) edit "So looooooong and nasty name of the variable" to move part "name..." below the row like:
"
So looooooong and nasty
name of the variable
"
However, when I write as "/nSo.../n" it gives another row of number from columns "OR" and "CIs".
How correct it?
r data-visualization forestplot
I prepared a code to visualize my data:
library(forestplot)
test_data <- data.frame(coef=c(1.14, 0.31, 10.70),
low=c(1.01, 0.12, 1.14),
high=c(1.30, 0.83, 100.16),
boxsize=c(0.2, 0.2, 0.2))
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
test_data <- rbind(rep(NA, 4), test_data)
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1,
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
It gives a following forestplot:
I would like to:
1) expand the plot and diminish font of the plot details on the left for better visualization
2) edit "So looooooong and nasty name of the variable" to move part "name..." below the row like:
"
So looooooong and nasty
name of the variable
"
However, when I write as "/nSo.../n" it gives another row of number from columns "OR" and "CIs".
How correct it?
r data-visualization forestplot
r data-visualization forestplot
asked Dec 30 '18 at 17:06
MikołajMikołaj
5710
5710
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Three possibilities (one more than you asked for):
1) change text of row labels with txt_gp
.
2) cut column spacing from 6 mm default to half that value by passing colgap
a grid call to unit. Fully understanding the options for forestplot
requires understanding the grid
system of plotting.
3) add a "n"
to the loooong label. (I'm puzzled you didn't see that possibility, since you already had a "n" in the title.)
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nnasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
title = gpar(cex = 1) ),
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
If I only used a cex of 0.7 in the call to gpar
passed to 'label', it also affected the size of the title, so I needed to "reset" the 'cex' of the 'title' back to 1.
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979701%2fforestplot-r-expanding-plot-edit-a-variable-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Three possibilities (one more than you asked for):
1) change text of row labels with txt_gp
.
2) cut column spacing from 6 mm default to half that value by passing colgap
a grid call to unit. Fully understanding the options for forestplot
requires understanding the grid
system of plotting.
3) add a "n"
to the loooong label. (I'm puzzled you didn't see that possibility, since you already had a "n" in the title.)
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nnasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
title = gpar(cex = 1) ),
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
If I only used a cex of 0.7 in the call to gpar
passed to 'label', it also affected the size of the title, so I needed to "reset" the 'cex' of the 'title' back to 1.
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
add a comment |
Three possibilities (one more than you asked for):
1) change text of row labels with txt_gp
.
2) cut column spacing from 6 mm default to half that value by passing colgap
a grid call to unit. Fully understanding the options for forestplot
requires understanding the grid
system of plotting.
3) add a "n"
to the loooong label. (I'm puzzled you didn't see that possibility, since you already had a "n" in the title.)
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nnasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
title = gpar(cex = 1) ),
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
If I only used a cex of 0.7 in the call to gpar
passed to 'label', it also affected the size of the title, so I needed to "reset" the 'cex' of the 'title' back to 1.
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
add a comment |
Three possibilities (one more than you asked for):
1) change text of row labels with txt_gp
.
2) cut column spacing from 6 mm default to half that value by passing colgap
a grid call to unit. Fully understanding the options for forestplot
requires understanding the grid
system of plotting.
3) add a "n"
to the loooong label. (I'm puzzled you didn't see that possibility, since you already had a "n" in the title.)
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nnasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
title = gpar(cex = 1) ),
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
If I only used a cex of 0.7 in the call to gpar
passed to 'label', it also affected the size of the title, so I needed to "reset" the 'cex' of the 'title' back to 1.
Three possibilities (one more than you asked for):
1) change text of row labels with txt_gp
.
2) cut column spacing from 6 mm default to half that value by passing colgap
a grid call to unit. Fully understanding the options for forestplot
requires understanding the grid
system of plotting.
3) add a "n"
to the loooong label. (I'm puzzled you didn't see that possibility, since you already had a "n" in the title.)
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nnasty name of the variable"),
c("OR", test_data$coef), c("CI -95%", test_data$low), c("CI +95%", test_data$high) )
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
title = gpar(cex = 1) ),
xlog = TRUE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
title="My Happy Happy Title n o happy happy title...n",
ci.vertices = TRUE,
xticks = c(0.1, 1, 10, 100))
If I only used a cex of 0.7 in the call to gpar
passed to 'label', it also affected the size of the title, so I needed to "reset" the 'cex' of the 'title' back to 1.
edited Dec 30 '18 at 18:27
answered Dec 30 '18 at 18:16
42-42-
213k15255399
213k15255399
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
add a comment |
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Nice, thanks for help. Do you know how decrease interval between plot and title?
– Mikołaj
Dec 31 '18 at 13:58
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
Well the first thing to do would be to remove the trailing "n" from the title text. I had noticed the large gap but figured that's what you wnated.
– 42-
Dec 31 '18 at 15:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53979701%2fforestplot-r-expanding-plot-edit-a-variable-name%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown