我有这个图表 - 我想在每个标签上添加文字N=xx来表示观察次数.我知道如何做到这一点,我已经在没有方面的图表上做到了.
当我在分面图表上尝试它时它不起作用(我在所有3个图表上的开放式刻度上获得了相同的N,在受限制的图表上获得相同的N等)
我希望有人可以指出解决方案,如何控制给定方面的元素?
library(ggplot2)
library(scales)
stat_sum_single <- function(fun, geom="point", ...) {
stat_summary(fun.y=fun, fill="red", geom=geom, size = 5, shape=24)
}
set.seed(1)
data1 <- data.frame(Physicians_In=sample(1:3,100,replace=T),Physicians_Out=sample(1:3,100,replace=T),share=runif(100,0,1))
data1$Physicians_In <- factor(data1$Physicians_In,levels=c(1,2,3),labels=c("Open","Restricted","Closed"))
data1$Physicians_Out <- factor(data1$Physicians_Out,levels=c(1,2,3),labels=c("Open","Restricted","Closed"))
access_ch3 <- ggplot(data1,aes(x=Physicians_In,y=share,fill=Physicians_In))+geom_boxplot()+stat_sum_single(mean)
access_ch3 <- access_ch3 +geom_jitter(position = position_jitter(width = .2),color="blue")+theme_bw()
access_ch3 <- access_ch3 + theme(legend.position="none") +scale_y_continuous("Gammagard Share",labels=percent)
gpo_labs5 <- paste(gsub("/","-\n",names(table(data1$Physicians_Out)),fixed=T),"\n(N=",table(data1$Physicians_Out),")",sep="")
access_ch3 <- access_ch3 + scale_x_discrete("Physician Access (In Hospital)",labels=gpo_labs5)
access_ch3 <- access_ch3 +facet_grid(.~Physicians_Out,labeller=label_both)
access_ch3
Run Code Online (Sandbox Code Playgroud)
我尝试创建9个标签并将该向量传递给scale_x_discrete元素,这只是回收了前3个,所以它也没有解决问题.
我试图模拟一些遵循S形曲线关系的数据.在我的工作领域(心理物理学)中,Weibull函数通常用于模拟这种关系,而不是概率.
我正在尝试使用R创建一个模型,并且正在努力学习语法.我知道我需要使用包中的vglm()功能VGAM,但我无法得到一个合理的模型.这是我的数据:
# Data frame example data
dframe1 <- structure(list(independent_variable = c(0.3, 0.24, 0.23, 0.16,
0.14, 0.05, 0.01, -0.1, -0.2), dependent_variable = c(1, 1,
1, 0.95, 0.93, 0.65, 0.55, 0.5, 0.5)), .Names = c("independent_variable",
"dependent_variable"), class = "data.frame", row.names = c(NA,
-9L))
Run Code Online (Sandbox Code Playgroud)
这是dframe1中的数据图:
library(ggplot2)
# Plot my original data
ggplot(dframe1, aes(independent_variable, dependent_variable)) + geom_point()
Run Code Online (Sandbox Code Playgroud)

这应该能够通过Weibull函数建模,因为数据符合S形曲线关系.以下是我对数据建模并生成代表性图的尝试:
library(VGAM)
# Generate model
my_model <- vglm(formula = dependent_variable ~ independent_variable, family = weibull, data = dframe1)
# Create a new …Run Code Online (Sandbox Code Playgroud) 我想计算从一组点到这些点的质心的多元距离.马哈拉诺比斯距离似乎适合这一点.但是,我收到一个错误(见下文).
任何人都可以告诉我为什么我会收到此错误,如果有办法解决它?
require(maptools)
occ <- readShapeSpatial('occurrences.shp')
load('envDat.Rdata')
#standardize the data to scale the variables
dat <- as.matrix(scale(dat))
centroid <- dat[1547,] #let's assume this is the centroid in this case
#Calculate multivariate distance from all points to centroid
mahalanobis(dat,center=centroid,cov=cov(dat))
Error in solve.default(cov, ...) :
system is computationally singular: reciprocal condition number = 9.50116e-19
Run Code Online (Sandbox Code Playgroud) 我试图使用从R中幸存的估计参数生成反Weibull分布.我的意思是我想,对于给定的概率(在MS Excel中实现的小型仿真模型中将是随机数),返回使用我的参数预计失败的时间.我理解逆Weibull分布的一般形式是:
X=b[-ln(1-rand())]^(1/a)
Run Code Online (Sandbox Code Playgroud)
其中a和b分别是形状和比例参数,X是我想要的失败时间.我的问题在于解释来自幸存的截距和协变量参数.我有这些参数,时间单位是天:
Value Std. Error z p
(Intercept) 7.79 0.2288 34.051 0.000
Group 2 -0.139 0.2335 -0.596 0.551
Log(scale) 0.415 0.0279 14.88 0.000
Scale= 1.51
Weibull distribution
Loglik(model)= -8356.7 Loglik(intercept only)= -8356.9
Chisq = 0.37 on 1 degrees of freedom, p= 0.55
Number of Newton-Raphson Iterations: 4
n=1682 (3 observations deleted due to missing values)
Run Code Online (Sandbox Code Playgroud)
我在帮助文件中读到R中的系数来自"极值分布",但我不确定这是什么意思以及我如何"回到"直接在公式中使用的标准比例参数.使用b = 7.79和a = 1.51给出了无意义的答案.我真的希望能够为基组和'Group 2'生成时间.我还应该注意,我自己没有进行分析,也无法进一步查询数据.
请使用以下代码:
<abbr title="World Health Organization">WHO</abbr>
Run Code Online (Sandbox Code Playgroud)
我们可以设置一个abbr标签的标题吗?那么我们可以使用标题来代替自定义工具提示吗?
我有一个数据框,如下面的示例.我想复制数据框中的列并重命名为另一个列名.
Name Age Rate
Aira 23 90
Ben 32 98
Cat 27 95
Run Code Online (Sandbox Code Playgroud)
欲望输出是:
Name Age Rate Rate2
Aira 23 90 90
Ben 32 98 98
Cat 27 95 95
Run Code Online (Sandbox Code Playgroud)
我该怎么做?谢谢.
我有一个从worldwildlife.org下载的shapefile,用于世界地球生态区.该文件可以在这里加载:http://worldwildlife.org/publications/terrestrial-ecoregions-of-the-world.
它是一个标准的形状文件,我想用它做两件事.首先:从我的本地目录中获取shapefile并将其剪辑到北美东部(ext = extent(-95,-50,24,63))
# Read shapefile using package "maptools"
eco_shp <- readShapeLines("F:/01_2013/Ecoregions/Global/wwf_terr_ecos.shp",
proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))
# Set the desired extent for the final raster using package "raster"
ext <- extent(-95, -50, 24, 63)
Run Code Online (Sandbox Code Playgroud)
我确信我必须在"raster"包中使用rasterize功能,但我仍然无法使其正常工作.我很感激有关如何做到这一点的任何建议.
给定树形图y,其在高度值z下具有k个簇,我想知道:
使用了多少观察数来形成聚类数(k)?
这里有一些可重现的代码和图片来说明问题:
#Necessary packages to reproduce the code
library(ggplot2)
library(cluster)
#Example data
x = c(6.2, 2.3, 0, 1.54, 2.17, 6.11, 0.3, 1.39,
5.14, 12.52, 12.57, 7.13, 13.71, 11.42,
8.13, 8.86, 9.97, 10, 8.23, 12.4, 9.51,
20.56, 17.78, 14.91, 19.17, 17.48, 17.44,
21.32,
21.24)
y = c(7.89, 7.63, 5.29, 8.38, 8.37, 10.5, 21.5,
16.65, 23.76, 1.77, 1.8, 10.49, 14.01,
10.36, 10.85, 15.02, 14.91, 14.94, 10.76,
18.58, 23.12, 0, 13.59, 9.68, 17.32, 17.85,
17.79, 4.13, 4.05)
df = data.frame(cbind(x,y))
obs = …Run Code Online (Sandbox Code Playgroud) 我正在创建一个非常简单的绘图,它将数据分组并使用分组变量来确定线条样式和颜色.然后我使用'scale_linetype_manaul'和'scale_colour_manual'覆盖那些.到目前为止一切都那么好,但是当我尝试修改图例标签或其标题时,图例分为两部分:一部分用于线型,一部分用于颜色.我只想要一个传奇,但有自定义标签和标题.
在这个问题之后,我确保将两个比例对象命名为相同,但这似乎没有帮助.
最小的例子:
X <- data.frame(TPP=factor(c(1,5,10,1,5,10,1,5,10)),
value=c(-0.035819, 0.003356, 0.066091, -0.028039, 0.004333, 0.060292, -0.023115, 0.005661, 0.058821),
horizon=c(1,1,1,2,2,2,3,3,3))
ggplot(X, aes(x=horizon, y=value, group=TPP, col=TPP, linetype=TPP))+
geom_line(size=1)+
scale_linetype_manual(name="X", values = c("solid","dashed", "dotted")) +
scale_color_manual(name="X", values = c("black", "red", "blue"), labels=c("Low", "5","High"))
Run Code Online (Sandbox Code Playgroud)
这产生了下图和两个图例.如何使用自定义标签和标题重新组合这些图例?
r ×9
ggplot2 ×2
weibull ×2
abbr ×1
colors ×1
css ×1
dataframe ×1
distance ×1
distribution ×1
legend ×1
line ×1
mahalanobis ×1
raster ×1
rasterizing ×1
shapefile ×1
similarity ×1
statistics ×1
vba ×1