如何在autoplot中放置不同的符号 [英] How to put different symbols in autoplot
问题描述
我在生存对象中遇到了 autoplot()
的一些麻烦。我将以下面的例子为例:
library(ggplot2)
library(ggfortify)
library )
datalung < - lung
fitlung < - survfit(Surv(time,status)〜sex,type =kaplan-meier,data = datalung)
autoplot(fitlung,conf。 int = FALSE,pVal = TRUE,pX = 800)+ scale_color_grey()
在上面的例子中,性别1和2具有不同的灰度级,只有2组可以看到不同的组。 p>
我正在使用的真实数据集有9个不同的组,很难看到具有此灰度的不同曲线。我不能使用颜色。我正在寻找的是一种将符号分配到不同组的方法,但我无法在 autoplot
中找到此参数。
surv.linetype
可以选择固体
和虚线
,但它会以相同的模式改变所有曲线,我不想要它。以肺
数据为例,我想为性别1和性别2设置不同的 linetype
。
仔细查看功能代码通常会帮助我弄清楚什么可以更改,哪些不能更改。您可以通过在控制台中运行 ggfortify ::: autoplot.survfit
来查看 autoplot.survfit
的代码。
仔细一看,您会看到只有 color
审美才能用于分组。我没有看到一个简单的方法来改变这一点,但你可以轻松地按照功能中的配方制作自己的情节。虽然构建自己的情节需要多一些步骤,但它给了你很大的灵活性。
fortify
模型,然后构建图。plot.data = fortify(fitlung,surv.connect = TRUE)
geom_point(data = subset(plot.data,n.censor> 0))+
ggplot(plot.data,aes(time,surv,shape = strata))+
geom_step(aes(linetype = (标签=标尺::百分比)
scale_y_continuous >
请注意,我只知道6种线型;即使有更多,他们将很难分开。形状并不好,但也有更多。
I'm having some troubles with autoplot()
in survival objects. I will take the below as example
library(ggplot2)
library(ggfortify)
library(survival)
datalung <- lung
fitlung<- survfit(Surv(time,status) ~ sex,type = "kaplan-meier",data=datalung)
autoplot(fitlung,conf.int=FALSE,pVal=TRUE,pX=800)+scale_color_grey()
In the example above, sex 1 and 2 have different grey scales, with just 2 groups it's fine to see the different groups.
The real dataset that I'm using have 9 different groups, and is hard to see the differents curves with this grey scale. I can't use colours. What I'm looking for is a way to put symbols to different groups, but I can't find this parameter in autoplot
.
The surv.linetype
have the option solid
and dashed
, but it changes all curves with same pattern and I don't want it. Taking the lung
data as example, I want to put different linetype
for sex 1 and sex 2.
Looking through the function code usually helps me figure out what can and cannot be changed. You can look at the code for autoplot.survfit
by running ggfortify:::autoplot.survfit
in the Console.
Looking through that you'll see only the color
aesthetic is used for groupings. I didn't see an easy way to change this, but you can easily follow the recipe in the function to make your own plot. While building your own plot takes a few more steps, it gives you a lot of flexibility.
For example, if you wanted to change the shape of the lines and points for each group you can fortify
the model and then build the plot.
plot.data = fortify(fitlung, surv.connect = TRUE)
ggplot(plot.data, aes(time, surv, shape = strata)) +
geom_step(aes(linetype = strata)) +
geom_point(data = subset(plot.data, n.censor > 0)) +
scale_y_continuous(labels = scales::percent)
Note that I only know of 6 line types; even if there were more they would be difficult to tell apart. Shapes aren't much better, although there are more of those.
这篇关于如何在autoplot中放置不同的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!