Related
I prepared the code for forestplot, however I have problem with exporting plot with "≥" / more or equal sign.
library(forestplot)
names6 <- c("Variable",
"A ≥ 4000***",
"B ≥ 50***",
"C**",
"D",
"E***",
"F",
"G*",
"H**",
"I*",
"J***")
coef6 <- c(0.42, 1.58, 1.35, 0.49,
0.46, 0.66, 0.62, 1.34, 0.52, 0.72)
low6 <- c(0.34, 1.29, 1.08, 0.21,
0.33, 0.44, 0.43, 1.08, 0.29, 0.61)
high6 <- c(0.51, 1.93, 1.69, 1.21,
0.64, 0.99, 0.91, 1.66, 0.92, 0.86)
boxsize6 <-c(0.2, 0.2, 0.2,0.2,
0.2,0.2, 0.2,0.2,
0.2, 0.2)
test_data <- data.frame(coef=coef6,
low=low6,
high=high6,
boxsize=boxsize6)
row_names <- cbind(names6,
c("OR",test_data$coef), c("CI-95%", test_data$low), c("CI+95%", test_data$high) )
test_data <- rbind(NA, test_data)
#####FIGURE
forestplot(labeltext = row_names,
mean = test_data$coef, upper = test_data$high,
lower = test_data$low,
is.summary=c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE),
boxsize = test_data$boxsize,
zero = 1,
xlog = FALSE,
xlab = "OR (95% CI)",
col = fpColors(lines="black", box="black"),
ci.vertices = TRUE,
xticks = c(0,0.5, 1, 1.5, 2.0),
colgap = unit(0.03,'npc'),
lineheight = unit(1.1,"cm"),
txt_gp=fpTxtGp(label = gpar(cex = 0.8),
title = gpar(cex = 1),
ticks = gpar(cex = 0.6),
xlab = gpar(cex = 0.7)))
However I cannot export plot as a .pdf file with present "≥" / more or equal.
Instead of this, I got sign "=" / equal.
What should I change to get this sign on plot?
Edit:
\u2265 do not work...
This solution might be system-specific. Here is something that works on windows:
library("forestplot")
library("withr")
names6 <- c("Variable",
"A \u2265 4000***",
"B \u2265 50***",
"C**",
"D",
"E***",
"F",
"G*",
"H**",
"I*",
"J***")
### Data & params code here....
with_cairo_pdf('forestplot.pdf',
### Forest plot code here....
forestplot(labeltext = row_names,
....)
)
I need to reorder the x-axis categorical variable with a numeric variable so the plot is simpler to follow with plotly, in R.
Here is some dummy data:
agg = structure(list(catvar = c("a", "b", "c", "d", "e", "f", "g",
"h", "i", "j", "k", "l", "m", "n", "o"), v1 = c(1.1, 1.3, 1,
0.8, 1.2, 1.4, 0.7, 2.5, 0.9, 2.5, 1.7, 0.9, 1.7, 1.1, 0.9),
v2 = c(0.1, 0.1, 0.1, 0, 0.1, 0.1, 0, 0.2, 0, 0.2, 0.1, 0.1,
0.1, 0.1, 0.1), v3 = c(7.3, 8.2, 6.4, 6, 7.5, 8.4, 5.8, 12.4,
6.4, 13.1, 9.3, 6.2, 9.4, 7.1, 6.3)), .Names = c("catvar",
"v1", "v2", "v3"), class = "data.frame", row.names = c(NA, -15L
))
Here is what I've been trying out. It seems recently a new feature was added to handle this but it's not working.
# the reordering is handled here:
ax <- list(
type = "category",
categoryorder = "array",
categoryarray = agg$catvar[order(agg[['v1']])],
showgrid = TRUE,
showticklabels = TRUE
)
p <- plot_ly(agg, x =~catvar,
y =~v2, name = 'v2',
type = 'scatter', mode = 'lines') %>%
add_trace(y =~v1, name = 'v1') %>%
add_trace(y =~v3, name = 'v3') %>%
layout(
xaxis = ax,
hovermode = 'x+y')
p
All I need is to re-order the x-axis (catvar) based on any of the numeric varaibles in the data.frame, these are v1, v2, v3.
You need to add to your code a command for reordering your dataset according to v1.
agg2 <- agg[order(agg[['v1']]),]
p <- plot_ly(agg2, x =~catvar,
y =~v2, name = 'v2',
type = 'scatter', mode = 'points') %>%
add_trace(y =~v1, name = 'v1') %>%
add_trace(y =~v3, name = 'v3') %>%
layout(
xaxis = ax,
hovermode = 'x+y')
p
This question is an extension of this particular question. I have this particular data.table. I'm using data.table, mc2d, and e1071 libraries
library("data.table")
library("mc2d")
library("e1071")
col <- c("COST","TIME")
dt <- structure(
list(
ID = c("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"),COST_PR_L = c(NA, 0.4, 0.31, 0.4, 0.5, 0.17, 1, 0.5, 0.5, 0.5),COST_PR_U = c(7.5, 2, 2.67, 1.67, 2.4,2, 1.5, 2, 2, 1.67),COST_PO_L = c(NA, 0.33, 0.25, 0.44,0.5, 0.25, 1, 0.5, 0.5, 0.5),COST_PO_U = c(3, 1.43, 3.33,1.8, 2.4, 3.6, 1.45, 2, 1.5, 1.67), TIME_PR_L = c(NA, 0.5,0.4, 0.5, 0.5, NA, 0.67, 0.5, 0.5, 0.5), TIME_PR_U = c(2,2.5, 3, 1.5, 2, NA, 1.5, 2, 1.67, 2), TIME_PO_L = c(NA,0.4, 0.25, 0.56, 0.5, NA, 0.6, 0.5, 0.5, 0.5), TIME_PO_U = c(2,2, 5, 1.67, 2.5, NA, 1.5, 2, 1.67, 2)
),.Names = c("ID","COST_PR_L", "COST_PR_U","COST_PO_L","COST_PO_U","TIME_PR_L","TIME_PR_U","TIME_PO_L","TIME_PO_U"),class = c("data.table","data.frame"),row.names = c(NA,-10L))
When I run this particular operation on it,
dt[, unlist(lapply(col, function(xx) {
y = colnames(dt)[grepl(pattern = xx, x = colnames(dt))]
vars1 = y[grepl(pattern = "PR", x = y)]
vars2 = y[grepl(pattern = "PO", x = y)]
mn = get(vars1[1])
mx = get(vars1[2])
sk1 = ifelse(mn !=0 && mx !=0,skewness(rpert(1000, min = mn , mode = 1, max= mx )),-1)
mn = get(vars2[1])
mx = get(vars2[2])
sk2 = ifelse(mn !=0 && mx !=0,skewness(rpert(1000, min = mn , mode = 1, max= mx )),-1)
return(list(sk1, sk2))
}), recursive = FALSE)
, by = "ID"]
I get the following error
Error in [.data.table(dt, , unlist(lapply(col, function(xx) { :
Column 1 of result for group 2 is type 'double' but expecting type
'logical'. Column types must be consistent for each group.
However, If I remove the unlist in the code, It seems to calculate the answer. What is unlist doing that is messing it up?
I have made a forest plot in r using the forestplot package. The code is as follows:
#forestplot
labeltext2 <- c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "Summary Effect")
effect2 <- c(0.12, 0.61, 0.11, 0.25, 0.24, 0.63, 0.33, 0.41, 0.38, 0.52, 0.23, 0.47,
0.32, 0.36, 0.03, 0.15, 0.25, 0.67, 0.003, 0.32)
lower_2 <- c(0.08, 0.51, .03, 0.11, 0.06, 0.62, 0.11, 0.29, 0.18,
0.4, 0.19, 0.39, 0.24, 0.39, -0.13, 0.01, 0.09, 0.43,
-0.08, 0.19)
higher_2 <- c(0.16, 0.71, .19, 0.39, 0.42, 0.64, 0.55, 0.53, 0.58,
0.64, 0.27, 0.55, 0.4, 0.4, 0.19, 0.29, 0.41, 0.91,
0.08, 0.44)
forestplot(labeltext2, effect2, lower_2, higher_2, zero = .32,
cex = 2,
lineheight = "auto",
xlab = "effect size",
xticks = c(-.5, 0, .5, 1, 1.5),
title = "ForestPlot",
new_page = TRUE)
Which allows me to get this image:
This image has an effect line coming up at .32, the summary effect, using the zero argument. I would like to add an additional thick black line at 0 to show the "no-effect" line. Does anyone know how do this? I am open to using another package/function.
Thank you!
I can't figure out how the forestplot uses grid graphics, but here's a manual solution:
forestplot(labeltext2, effect2, lower_2, higher_2, zero = .32,
cex = 2,
lineheight = "auto",
xlab = "effect size",
xticks = c(-.5, 0, .5, 1, 1.5),
title = "ForestPlot",
new_page = TRUE)
# Add line manually
x = .397
y0 = .12
y1 = .875
grid.lines(c(x, x), c(y0, y1), default.units = "npc",
gp = gpar(lwd = 2))
This question already has answers here:
Pattern matching using a wildcard
(6 answers)
Robust se. (vcovHC) to be shown with texreg in R
(1 answer)
Closed 6 years ago.
I do generate robust standard errors with library(sandwich)
e.g.
library(sandwich)
cov.xxx <- vcovHC(xxx, type = "HC")
rob.std.err.xxx <- sqrt(diag(cov.xxx))
Then I would like to integrate that in a Latex export presenting several models in parallel. That works "well". I use
library(texreg)
texreg(list(x, xx, xxx, xxxx),
custom.model.names = c("1", "2", "3", "4"),
custom.coef.names = c("Constant",
"A", "B", "C", "D", "E", "F", "G", "H","I", "J", "K", "L",
"Wrong Sequenced Element",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X"),
groups = list("Var1" = 1:5,
"Var2" = 6:14,
"Var3" = 15:19, "Var4" = 20:25),
sideways = T,
single.row = T,
override.se = list(c(0.1,0.1, 0.1, 0.1, 0.1),
c(0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1),
c(0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
0.1, 0.1, 0.1, 0.1, 0.1),
**rob.std.err.xxx #values from robust regression**
),
caption= "zzz",
return.string = TRUE, use.packages = FALSE , booktabs = TRUE, dcolumn = TRUE, digits = 3,
file = paste0(tablesdir, "xxxx.tex"))
However the order of attributes in rob.std.err.xxx does not correspond to my LM model. And I cannot figure out how to alter the SE override properly. If anybody can advise on the same procedure on p-values that would be very much appreciated!
All I would need is to alter the sequence in the rob.std.err.xxx and then export it into my target structure indicated above.
This question refers mainly to a texreg "issue". But as mentioned in the comment a solution exists.
Thanks in advance for any support.