我用这段代码制作了这个图:
plot(p, cv2,col=rgb(0,100,0,50,maxColorValue=255),pch=16,
panel.last=abline(h=67,v=1.89, lty=1,lwd=3))
Run Code Online (Sandbox Code Playgroud)
我的情节看起来像这样:

1.)如何在简单的情节中绘制下划线的值?
2.)我如何缩放我的情节以使两条线都出现在中间?
您能帮我弄清楚为什么我会收到错误吗?
最初我的数据如下所示:
> attributes(compl)$names
[1] "UserID" "compl_bin" "Sex.x" "PHQ_base" "PHQ_Surv1" "PHQ_Surv2" "PHQ_Surv3"
[8] "PHQ_Surv4" "EFE" "Neuro" "Intervention.x" "depr0" "error1_1.x" "error1_2.x"
[15] "error1_3.x" "error1_4.x" "stress0" "stress1" "stress2" "stress3" "stress4"
[22] "hours1" "hours2" "hours3" "hours4" "subject"
Run Code Online (Sandbox Code Playgroud)
首先,我重塑数据以准备 geeglm:
compl$subject <- factor(rownames(compl))
nobs <- nrow(compl)
compl_long <- reshape(compl, idvar = "subject",
varying = list(c("PHQ_Surv1", "PHQ_Surv2" ,
"PHQ_Surv3", "PHQ_Surv4"),
c("error1_1.x", "error1_2.x",
"error1_3.x", "error1_4.x"),
c("stress1", "stress2", "stress3",
"stress4"),
c("hours1", "hours2", "hours3",
"hours4")),
v.names = c("PHQ", "error", "stress", "hours"),
times = c("1", "2", "3", "4"), direction …Run Code Online (Sandbox Code Playgroud) > library(vcd)
Loading required package: MASS
Loading required package: grid
Loading required package: colorspace
> library(MASS)
> tbl = table(survey$W.Hnd,survey$Fold)
> print(tbl)
L on R Neither R on L
Left 10 1 7
Right 88 17 113
> mosaic(tbl)
Error in if (split_vertical[i]) { : missing value where TRUE/FALSE needed
Calls: mosaic -> mosaic.default -> strucplot -> labeling
Execution halted
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误,以及如何修复代码?
简单粘贴代码在这里:
library(vcd)
library(MASS)
tbl = table(survey$W.Hnd,survey$Fold) # survey is a library data set in MASS
print(tbl)
mosaic(tbl) # produces …Run Code Online (Sandbox Code Playgroud) 我有一些数据dt = data.table(x=c(1:200),y=rnorm(200)),我开始使用密度图ggplot2:
plot = ggplot(dt,aes(y)) + geom_density(aes(y=..density..))
Run Code Online (Sandbox Code Playgroud)
有没有办法可以添加类似于此的百分位线?
如果进一步的我能遮荫的图形相似(由百分线创建)的段这个,那么这将是伟大的!
我在R中有重叠点的数据.
x = c(4,4,4,7,3,7,3,8,6,8,9,1,1,1,8)
y = c(5,5,5,2,1,2,5,2,2,2,3,5,5,5,2)
plot(x,y)
Run Code Online (Sandbox Code Playgroud)
如何绘制这些点以使重叠点比例大于非点.例如,如果3点位于(4,5),那么位置(4,5)处的点应该是仅有一个点的点的三倍.
我是regex的全新手,所以这个问题对你们许多人来说似乎微不足道.我想提取第二个和第三个逗号之间的单词,如句子中所示:
Chateau d'Arsac, Bordeaux blanc, Cuvee Celine, 2012
Run Code Online (Sandbox Code Playgroud)
我试过了:(?<=,\s)[^,]+(?=,)但这并不能归还我想要的东西......
我想用简单(但很糟糕)的数据集做一个简单的成对wilcox测试.我有8组,每组有5个值(见下面的数据).这些组在列"id"中,并且感兴趣的变量(在这种情况下是权重)是"权重".我尝试的是:
pairwise.wilcox.test(dat$weight,dat$id, p.adj = "bonf")
Run Code Online (Sandbox Code Playgroud)
这给了我以下结果:
286x306 286x339 286x574 547x286 574x519 574x542 574x547 587x210 589x286
286x339 0.36 - - - - - - - -
286x574 1.00 1.00 - - - - - - -
547x286 0.36 1.00 0.36 - - - - - -
574x519 0.36 0.36 0.36 0.72 - - - - -
574x542 0.36 0.36 0.36 0.36 0.36 - - - -
574x547 0.36 0.36 0.36 1.00 0.36 0.36 - - -
587x210 1.00 1.00 1.00 0.36 …Run Code Online (Sandbox Code Playgroud) 有没有办法编写一个函数,其中一个参数指示要应用的函数?
例如,如果我有一个功能:
mf = function(data, option, level)
Run Code Online (Sandbox Code Playgroud)
在这里我想选项来告诉是否计算mean,median或sd数据集的?
有人可以解释为什么在下面的示例中,列名称why似乎仍然保留,x即使它已明确命名why并且可以这样调用但不是列zz?
df<-data.frame(x=1:5,y=1:5)
df$z<-"a"
df$zz<-df$x*df$y
df$why<-df[1]*df[2]
df
df["why"]
Run Code Online (Sandbox Code Playgroud) 如果我有以下数据并使用ggplot2我得到它:
a <-c(0.3,0.3,0.3,0.3,0.3)
b <-c(1:5,0.9,0.9,0.9,0.9,0.9)
c <-c(1:5,0.5,0.5,0.5,0.5,0.5)
z <-rep(1:5,5)
df <- data.frame(y=c(a,b,c),x=c(z),line=c(rep("1",5),
rep("2",5),rep("3",5),rep("2",5),rep("3",5)))
library(ggplot2)
a <- ggplot(df,aes(x=x,y=y,fill=line,shape=line,group=line)) +
geom_line(aes(linetype=line),size=1) +
scale_linetype_manual(values=c("dashed","solid", "dotdash")) +
geom_point(size=3) + scale_shape_manual(values=c(25,23,21,25,23)) +
scale_fill_manual(values=c("red", "blue", "yellow","red", "blue"))
Run Code Online (Sandbox Code Playgroud)
如果我想指定图例的标题,我可以做很多事情
a + labs(shape = "MY TITLE HERE") # or
a <- ggplot(df,aes(x=x,y=y,fill=line,shape=line,group=line)) +
geom_line(aes(linetype=line),size=1) +
scale_linetype_manual(values=c("dashed","solid", "dotdash")) +
geom_point(size=3) + scale_shape_manual(values=c(25,23,21,25,23),name="MY
TITLE HERE") +
scale_fill_manual(values=c("red", "blue", "yellow","red", "blue"))
Run Code Online (Sandbox Code Playgroud)

但是,所有这些选项都会将复合图例分解为单独的映射参数.
如何维护与复合的传说linetype,shape以及fill和更改图例标题?
r ×9
ggplot2 ×2
plot ×2
comparison ×1
dataframe ×1
difference ×1
python ×1
regex ×1
statistics ×1