请p在下面找到数据样本。我制作了以下内容ggsurvplot:
我想从自动打印的图例中删除带圆圈的“地层”文本。我认为这是多余的,破坏了“图形平衡”。
当我运行这个脚本时它会打印:
#Fit the data
fit <- survfit(Surv(p$rfs, p$recurrence) ~ p$test, data=p)
#Plot
j <- ggsurvplot(
fit,
data = p,
risk.table = TRUE,
pval = TRUE,
pval.coord = c(0, 0.25),
conf.int = T,
legend.labs=c("TERTp-wt (all)", "TERT-alt (all)"),
size=0.7,
xlim = c(0,50),
#alpha=c(0.4),
conf.int.alpha=c(0.1),
break.x.by = 6,
xlab="Time in months",
ylab="Probability of recurrence-free survival",
ggtheme = theme,
surv.median.line = "v",
ylim=c(0,1),
tables.theme=theme,
surv.scale="percent",
tables.col="strata",
risk.table.col = "strata",
risk.table.y.text = FALSE,
tables.y.text = FALSE)
j$table <- j$table …Run Code Online (Sandbox Code Playgroud) 请在My data q下面找到。
我有两个协变量:q$Studie和q$best.resp对应于每个五个不同的研究报告一定的处理后得到的最好回应。
q$best.resp 有三个层次
table(q$best.resp)
0 1 2
62 42 2
Run Code Online (Sandbox Code Playgroud)
我想,以产生表示各直方图q$best.resp每所有q$Studie和所有研究组合(对应于table(q$best.resp))
我已经画了这个例子,说明我希望情节看起来如何。不幸的是,我没有通过手册获得成功。
我更喜欢ggplot2中的解决方案。请注意,所有研究仅包含q$best.resp==0或q$best.resp==1-,但单独q$Studie==5包含两种情况q$best.resp==2
My data
q <- structure(list(Studie = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, …Run Code Online (Sandbox Code Playgroud) 我正在尝试想象 Covid-19 之前和之后的外科手术:
正如你所看到的,我的geom_rect()颜色与geom_point().
我希望蓝色color和fill是geom_rect()半透明的,类似fill = alpha("#2C77BF", .5)). 但是,当使用下面的脚本时,alpha-部分不起作用。
geom_rect()如何获得与指定的颜色不同的半透明度geom_point()?
ggplot(b,
aes(x = cons_week, y = n, color = corona, fill = corona)) +
geom_point(size = 5, shape = 21) +
geom_smooth(se = F, method = lm, color = "black", show.legend = F) +
geom_smooth(lty = 2, show.legend = F) +
geom_segment(aes(x = 167, xend = 167, y = 2.5, yend = 25), …Run Code Online (Sandbox Code Playgroud) 请p在下面找到我的数据样本。
问题:为什么条带文本颜色facet_wrap()没有按照 中指定的那样改变element_text(colour)?
我制作了这个情节
我想带文本颜色(UICC Stage I, II, III and IV)到的颜色匹配geom_point中指明cols。它当前加载#E1B930到所有文本项上。
以下脚本有什么问题?
cols = c("#E1B930", "#2C77BF","#E38072","#6DBCC3")
ggplot(p, aes(x=n.fjernet,y=os.neck)) + geom_point(aes(color=uiccc),shape=20, size=5,alpha=0.7) +
geom_quantile(quantiles = 0.5,col="black", size=1,linetype=2) + facet_wrap(.~factor(uiccc)) +
scale_fill_manual(values=cols) +
scale_colour_manual(values=cols) +
scale_x_continuous(breaks = seq(0,50, by=10), name="Lymph nodal yield") +
scale_y_continuous(name="Time to death") +
theme(strip.text.x = element_text(size=12,face="bold", colour = cols),
strip.text.y = element_text(size=12, face="bold"),
strip.background = element_rect(fill="white"),
legend.position="none")
Run Code Online (Sandbox Code Playgroud)
我的资料
p <- structure(list(uiccc = structure(c(4L, …Run Code Online (Sandbox Code Playgroud) 我希望 56 显示在 x 轴上,但我无法弄清楚。
我有以下脚本。我尝试将以下内容添加到脚本中xlim = c(seq(0,100, by=10),56),但这似乎不起作用。
我尝试用谷歌搜索它并阅读了 R 文档。我希望你能帮忙。
library(survival)
library(survminer)
library(ggplot2)
fit <- survfit(Surv(p$time.recur.months, p$recurrence) ~ p$simpson.grade,
conf.type="log", data=p)
j <- ggsurvplot(
fit,
data = p,
fun="cumhaz",
risk.table = TRUE,
pval = TRUE,
pval.coord = c(0, 0.25),
conf.int = F,
legend.labs=c("Simpson Grade 1" ,"Simpson Grade 2", "Simpson Grade 3",
"Simpson Grade 4"),
size=c(0.7,0.7,0.7,0.7),
xlim = c(0,100),
alpha=c(0.7),
break.time.by = 10,
xlab="Time in months",
#ylab="Survival probability",
ggtheme = theme_gray(),
risk.table.y.text.col = T,
risk.table.y.text = TRUE, …Run Code Online (Sandbox Code Playgroud) 我使用组合了三个图patchwork
我已经关注了这个SO线程,其中解决了类似的问题。但是,在我的脚本上应用该特定方法并不能解决问题。我想要所有三个图都有一个共同的图例:
脚本
library(ggplot2)
tti_type <- ggplot(p %>%
bind_rows(., mutate(., type = "all")),
aes(x = type, y = logtti, color = corona, fill = corona)) +
geom_boxplot() +
scale_color_manual(name="",
values = c("#8B3A62", "#6DBCC3"),
label = c("Before", "During lockdown")) +
scale_fill_manual(name = "",
values = c("#8B3A6220", "#6DBCC320"),
label = c("Before", "During lockdown")) +
ggtitle("Time to treatment initiation") +
theme(legend.position = "bottom")
los_type <- ggplot(p %>%
bind_rows(., mutate(., type = "all")),
aes(x = type, y = loglos, …Run Code Online (Sandbox Code Playgroud) 我有以下情节
正如您可能在图片中看到的那样,右侧有一个灰色背景,标有黑色箭头,其中列出了X-negative和(您可以加载数据和脚本来亲自查看,请参见下文)。X-positive
我希望特定的灰色背景成为白色背景。我怎样才能改变这一点?
我使用以下定制设计。请在下面找到一个数据样本,用w1和表示w2。
# Custom designed theme
theme <- theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_line(colour = "gray98"),
panel.grid.minor = element_line(colour = "gray98"),
panel.border = element_blank(),
panel.background = element_blank())
Run Code Online (Sandbox Code Playgroud)
和
# My script
df <- data.frame(x = as.factor(c(w1$ny_stadie, w2$ny_stadie)),
y = c(w1$n.fjernet, w2$n.fjernet),
f = rep(c("N+", "N0"), c(nrow(w1), nrow(w2))))
df <- df[!is.na(df$x),]
ggplot(df) +
geom_boxplot(aes(x, y, fill = f, colour = f), outlier.alpha = 0, position = position_dodge(width = …Run Code Online (Sandbox Code Playgroud) 我制作了这个情节library(ComplexHeatmap)
我希望Z-score位于底部位置,而分类变量显示在右侧。这篇文章rowAnnotation很接近,但我无法像下面的脚本一样使用它。
预期产出
有了这些数据:
set.seed(123)
library(ComplexHeatmap)
mat = matrix(rnorm(96, 2), 8, 12)
mat = rbind(mat, matrix(rnorm(48, -2), 4, 12))
hmap <- as.data.frame(t(mat))
hmap$type <- rep(c("Ctrl", "Cell_type1", "Cell_type2"), 4)
hmap$malig <- ifelse(hmap$type == "Ctrl", "Ctrl", "Tumor")
hmap_bt <- scale(as.matrix(hmap[, -c(13:14)]))
Run Code Online (Sandbox Code Playgroud)
并使用这个脚本
draw(Heatmap(hmap_bt,
name = "Z-score",
col = colorRamp2(c(-2, 0, 2), c("#6DBCC3", "white", "#8B3A62")),
show_column_names = FALSE,
show_column_dend = FALSE,
column_km = 3,
left_annotation = rowAnnotation(Case = hmap[, c(13:14)]$malig,
Type = hmap[, c(13:14)]$type,
col = list(Case …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 ggplot2 中制作图表。我希望 x 轴显示 2.84 以及下面键入的序列。除了在 break() 中输入所有确切值之外,还有其他方法吗?我试过谷歌,但它没有解决我的问题。
scale_x_continuous(limits = c(1, 7), seq(1,7,by=0.5), name = "Number of
treatments")
Run Code Online (Sandbox Code Playgroud) 问题:是否可以在和 中指定的同一标签文本中同时使用plain和solid文本字体?scale_fill_manualscale_color_manual
我有
写于
ggplot(p, aes(x=value, y=os.neck, color=name_new, fill=name_new)) +
theme(axis.text.x = element_text(size=12, hjust=0)) +
geom_point(size=2.2, shape=21, stroke=1, fill=alpha("white", .7)) +
geom_quantile(quantiles=.5, size=1.3) +
scale_color_manual(values = c("#2C77BF", "#E38072", "#E1B930"),
name="",
labels=c("Lymph nodal yield\nUICC Stage I and II\nn=292", "Lymph nodal yield\nUICC Stage III and IV\nn=138","Lymph node density\nUICC Stage III and IV\nn=138")) +
scale_fill_manual(values = c("#2C77BF", "#E38072","#E1B930"),
name="",
labels=c("Lymph nodal yield\nUICC Stage I and II\nn=292", "Lymph nodal yield\nUICC Stage III and IV\nn=138","Lymph node density\nUICC Stage …Run Code Online (Sandbox Code Playgroud) 我希望在不改变 ggtheme 的情况下添加一个坚实的浅灰色网格ggsurvplot- 与 ggplot() 中的相当grids(linetype="solid")。
我的数据
p <- structure(list(Studie = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L), Age = c(35, 38, 67, 18, 62, 61, 31, 34, 26, 44, 33, 54, 35, 49, 62, 56, 41, 58, 65, 29,63, 63, 51, 56, 44, 45, 47, 67, 56, 54, …Run Code Online (Sandbox Code Playgroud) 我有这个 ROC 曲线
用这段代码编写:
ggplot(a, aes(y = TPR, x = FPR, color = model)) +
geom_line() +
geom_segment(aes(y = 0, yend = 1, x = 0, xend = 1), color = "grey50")
Run Code Online (Sandbox Code Playgroud)
我想对红色和绿色曲线之间的空间以及绿色曲线和对角线之间的区域进行着色。
我尝试徒手手动为预期输出着色(我对艺术技巧表示歉意)
我寻求解决方案geom_area(),但无法使其发挥作用。
我怎样才能填充这些区域?
这是我的数据样本。我对许多数据点表示歉意,但这是我能够重现达到 (0,0) 和 (1,1) 的“完整曲线”的唯一方法。
a <- structure(list(model = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, …Run Code Online (Sandbox Code Playgroud)