我希望在我的情节中得到一个破X轴.在x轴上,我喜欢插入一个断轴符号< // >[从2开始到8结束,这意味着2-8将隐藏在< // >符号中],因此可以强调其他值.在Matlab中,此任务通过使用BreakXAxis执行.在R中,plotrix库只能插入一个断轴符号,就是这样.
x <- c(9.45, 8.78, 0.93, 0.47, 0.24, 0.12)
y <- c(10.72, 10.56, 10.35, 10.10, 9.13, 6.72)
z <- c(7.578, 7.456, 6.956, 6.712, 4.832, 3.345)
plot(x, y, col='blue', pch=16, xlab= 'x', ylab='y, z')
points(x, z, col='red', pch=17)
library(plotrix)
axis.break(1,2,style="slash")
Run Code Online (Sandbox Code Playgroud) 我不确定究竟该怎么称呼它,但我试图实现一种"破碎的直方图"或"轴间隙"效应:http://gnuplot-tricks.blogspot.com/2009/11/broken- histograms.html(例如在gnuplot中)与R.
看起来我应该使用包中的gap.plot()函数plotrix,但我只看到了使用散点图和线图的示例.我已经能够在我的情节周围的框中添加一个中断并在其中放置一个曲折,但我无法弄清楚如何重新缩放我的轴以放大休息下方的部分.
重点是能够在我的直方图中显示一个非常大的条形的最高值,同时放大我的大多数明显更短的箱子.(是的,我知道这可能会产生误导,但如果可能的话,我仍然希望这样做)
有什么建议?
更新5/10/2012 1040 EST:
如果我使用数据进行常规直方图并使用< - 将其保存到变量(hdata <- hist(...))中,我会得到以下变量的以下值:
hdata$breaks
[1] 0.00 0.20 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.30 0.31 0.32 0.33
[16] 0.34 0.35 0.36 0.37 0.38 0.39 0.40 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48
[31] 0.49 0.50 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.60 0.61 0.62 0.63
[46] 0.64 0.65 0.66 0.67 0.68 0.69 0.70 …Run Code Online (Sandbox Code Playgroud) 我试图在Taylor图中绘制多个模型,并且在代码中稍微挣扎.我已设法生成图表(见图)但无法弄清楚如何减小轴,因为它们太大,标准化标记为1,2,3,4的轴并在相关性上添加刻度线 - 用勾号标记我希望每0.1一次有一个主要的刻度,每0.05到0.9就有一个小刻度,之后我试图在0.95处有一个主要的刻度,此时每0.01都有一个小刻度(如果这是有道理的).任何有关上述的帮助/建议都会有所帮助.我在'plotrix'包中使用了'taylor.diagram'(并阅读了它的指南 - 但我对R相对缺乏经验)并且附加了我的(有点基本的)代码到目前为止,但我的情节看起来相当混乱.谢谢
all.models <- as.data.frame(cbind(Sy.One, Sy.Two, Sy.Three, Sy.Four, Sy.Five, Sy.Six, Sy.Seven, Sy.Eight, Sy.Nine, Sy.Ten))
taylor.diagram(CSR, Sy.One, sd.arcs=T, ref.sd=T, pcex=1.5, main=NULL, pos.cor=F,
xlab="Standard Deviation (cm)", ylab="Standard Deviation (cm)")
for (i in 1:dim(all.models)[2]) {
model.wanted <- all.models[,i]
taylor.diagram(CSR, model.wanted, sd.arcs=T, ref.sd=T, pcex=1.5, col=i, add=T, pos.cor=F)}
# Add legend
model.names <- c("Sy=1%","Sy=2%","Sy=3%","Sy=4%","Sy=5%","Sy=6%","Sy=7%","Sy=8%","Sy=9%","Sy=10%")
legend("top", model.names, pch=19, col=i, cex=1.0, bty="n", ncol=5)
Run Code Online (Sandbox Code Playgroud)

我可以轻松地使用ggplot2绘制如下图:

事实上,对于我的数据,它如下所示:
degree value 1 120 0.50 2 30 0.20 3 -120 0.20 4 60 0.50 5 150 0.40 6 -90 0.14 7 -60 0.50 8 0 0.60
第一列是度(从-180到180或从0到360),第二列是对应的值.所以我想用箭头绘制从(0,0)到每个数据点的图形点,但是如下所示:
2 http://www.matrixlab-examples.com/image-files/polar_plots_1.gif
我尝试使用以下代码:
base <- ggplot(polar, aes(x=degree, y=value))
p <- base + coord_polar()
p <- p + geom_segment(aes(x=0, y=0, xend=degree, yend=value ), arrow=arrow(length=unit(0.3,"cm")) )
print(p)
Run Code Online (Sandbox Code Playgroud)
它产生了一个极坐标图,但我没有得到从(0,0)到我的数据点的直箭头.
我也尝试使用plotrix包来绘制这个图.它的工作原理如下:
3 http://rgm2.lab.nig.ac.jp/RGM_results/plotrix:polar.plot/polar.plot_001_med.png
我无法在此图表中导入箭头.
如何使用plotrix包添加箭头,或者如何使用ggplot2绘制箭头?
我想创建一个数字(与附件类似),ggplot2其中圆形代表一年中的月份,因此圆周上有十二个刻度线,并且某个颜色的内圆弧对应于其中pa= 1的月份(其他选项)是pa= 0)和对应于sampled= 1的另一个内弧(在第一弧的外部)(其他选项是sampled= 0)。数据如下所示:
m
season pa month sampled occupancy
1 spring 1 3 1 present
2 spring 1 4 1 present
3 spring 1 5 1 present
4 summer 1 6 1 present
5 summer 1 7 1 present
6 summer 1 8 1 present
7 winter 0 12 1 absent
8 winter 0 1 0 absent
9 winter 0 2 0 absent
10 fall 1 9 1 …Run Code Online (Sandbox Code Playgroud) 从包中boxplot()使用时,异常值会丢失,而不是 R 自己的。我试着理解为什么。gap.boxplot()plotrix
请看这个例子:
> mtcars[2,c('mpg')] <- 45
> mtcars[6,c('mpg')] <- 77
Run Code Online (Sandbox Code Playgroud)
使用boxplot(mtcars$mpg)您可以在箱线图顶部看到两个额外的点(异常值)。
在该图形中使用gap.boxplot(mtcars$mpg)from plotrixpackage 结果
最大的问题是为什么以及如何解决这个问题?
我正在使用 plotrix 包来绘制圆圈。
而且我不明白我的代码有什么问题...... :-(
我有三分。第一个点(1,1)应该是圆的中心。以下两点(1,4),并(4,1)具有相同的距离/半径的中心。所以图中的圆圈应该经过这些点,对吧?
而且我不知道为什么圆圈看起来不对。有解释吗?
p1 <- c(1,1)
p2 <- c(4,1)
p3 <- c(1,4)
r <- sqrt(sum((p1-p2)^2))
plot(x=c(p1[1], p2[1], p3[1]),
y=c(p1[2], p2[2], p3[2]),
ylim=c(-5,5), xlim=c(-5,5))
draw.circle(x=p1[1], y=p1[2], radius=(r))
abline(v=-5:5, col="#0000FF66")
abline(h=-5:5, col="#0000FF66")
Run Code Online (Sandbox Code Playgroud)
在这里查看生成的输出
我有一个带有两个对数轴的图.我想在情节的某个位置添加一个圆圈.我尝试使用plotrix,但这不提供"log-radius"的选项.
# data to plot
x = 10^(-1 * c(5:0))
y = x ^-1.5
#install.packages("plotrix", dependencies=T)
# use require() within functions
library("plotrix")
plot (x, y, log="xy", type="o")
draw.circle(x=1e-2, y=1e2, radius=1e1, col=2)
Run Code Online (Sandbox Code Playgroud)
如何在记录日志中添加圆圈?
我想在同一个图上创建一个包含多个数据系列的直方图.我能找到的最佳方法是multhist().我想要一个类似的风格的情节hist(),虽然ggplot()也可以用来执行这个任务,图形样式不是我想要的.
以下是一些示例数据:
df <- structure(list(year = c(2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L), count = c(187L, 199L, 560L, 1000L, 850L,
400L, 534L, 911L, 390L, 1008L, 1173L, 1222L, 810L, 950L, 752L,
1125L, 468L, 710L, 290L, 670L, 855L, …Run Code Online (Sandbox Code Playgroud) 我想摆脱X和Y值(图片上的红线)接近零的小边距,并仅绘制红色方块中显示的内容。
我尝试设置par(mar = rep(0, 4)和xlim=c(0, ...),ylim=c(0, ...)但是R仍然继续添加这个很小的边距。如何摆脱它?
编辑:关于我的问题的另一种观点:运行后:
require(plotrix)
axisRange <- c(0,500)
plot(NULL, xlim = axisRange, ylim=axisRange)
draw.circle(0, 0, 200, col = "white", border = "red")
Run Code Online (Sandbox Code Playgroud)
EDIT2:实际上我想做的是绘制不同半径的圆,并将其保存为图像。这就是为什么我在乎利润。我最终得到这样的结果(角落上的斑点仅供参考):
我用ggplot2创建了一个图。这与牛奶中的蛋白质含量有关。我有两组和4种治疗方法。我想展示组和处理,均值和错误栏之间的相互作用。蛋白质含量从2.6%开始。现在,我的y轴从那里开始没有间隙,但是我的主管希望有一个。我尝试了plotrix库的axis.break(),但没有任何反应。我试图用gap.plot重建图形,但没有成功,但我必须承认我不是R英雄。
这是我的图形的代码:
Protein<-ggplot(data=D, aes(x=treat, y=Prot,group=group, shape=group))+
geom_line(aes(linetype=group), size=1, position=position_dodge(0.2))+
geom_point(size=3, position=position_dodge(0.2))+
geom_errorbar(aes(ymin=Prot-Prot_SD,ymax=Prot+Prot_SD), width=.2,
position=position_dodge(0.2))+
scale_shape_discrete(name='group\n', labels=c('1\n(n =
22,19,16,20)\n','2\n(n = 15,12,14,12)'))+
scale_linetype_discrete(name="group\n", labels=c('control\n(n =
22,19,16,20)\n','free-contact\n(n = 15,12,14,12)'))+
scale_x_discrete(labels=c('0', '1', '2', '3'))+
labs(x='\ntreatment', y='protein content (%)\n')
ProtStar<-Protein+annotate("text", x=c(1,2,3,4), y=c(3.25,3.25,3.25,3.25),
label=c("Aa","Aa","Ab","Ba"), size=4)
plot(ProtStar)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我没有足够的声誉来发布图像,但是您可能从代码中看到图形很复杂。
如果您有有用的建议,那就太好了。非常感谢!
我正在使用包中的taylor.diagram功能,plotrix例如
obs = runif(100,1,100)
mod1 = runif(100,1,100)
mod2 = runif(100,1,100)
mod3 = runif(100,1,100)
taylor.diagram(obs,mod1)
taylor.diagram(obs,mod2,add=TRUE)
taylor.diagram(obs,mod3,add=TRUE)
Run Code Online (Sandbox Code Playgroud)

在传统的泰勒图中没有偏见,但在他的论文中(Taylor,2001,KE总结模型性能的多个方面,在单个图中Taylor JGR,106,7183-7192)泰勒说
"Although the diagram has been designed to convey information about centered pattern differences it is also possible to indicate differences in overall means (i.e., the bias). This can be done on the diagram by attaching to each plotted point a line segment drawn at a right angle to the straight line defined by the point and the reference …
嘿我想在R中绘制几个不同半径的圆圈.
我用'plotrix'和draw.circle做了这个:
draw.circle (0,0,1)
draw.circle (0,0,1.5)
draw.circle (0,0,2)
...
Run Code Online (Sandbox Code Playgroud)
你知道更快更智能的方法吗?