相关疑难解决方法(0)

将表达式(plotmath)放在图例键标签中

如何将表达式(plotmath)放入下图的图例键标签中?

我知道如何在ggplot2中使用希腊符号?和其中的链接,但每当我使用scale_..._manual功能,我获得第二个传奇(见下文).

require(ggplot2)
require(reshape2)
require(plyr)

## parameters
d <- c(2, 5, 10, 20, 50, 100)
tau <- c("t1", "t2", "t3")
fam <- c("f1", "f2", "f3", "f4", "f5")
meth <- c("m1", "m2", "m3", "m4")

## lengths
nd <- length(d)
ntau <- length(tau)
nfam <- length(fam)
nmeth <- length(meth)

## build result array containing the measurements
arr <- array(rep(NA, nd*ntau*nfam*nmeth), dim=c(nd, ntau, nfam, nmeth),
             dimnames=list(d=d, tau=tau, fam=fam, meth=meth))
for(i in 1:nd){
    for(j in 1:ntau){
        for(k in 1:nfam){
            for(l …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

4
推荐指数
1
解决办法
905
查看次数

ggplot2中的希腊符号:geom_boxplot

我试图在ggplot2中制作的箱形图中加入希腊符号.然而,在经历了关于堆栈溢出的所有先前的问题后,我不能为我的生活让他们的任何示例工作.

对转发道歉,但如果有人能帮助我,我会非常感激.

我的代码到目前为止是:

## Data
names = LETTERS[1:3]
x = runif(99)
y = rep(names, length = length(x))
Parameters = factor(rep(c("Lambda", "Phi", "Gamma"), each = length(names)), 
                    levels = c("Lambda", "Phi", "Gamma"))
plot.df = data.frame(x, y, Parameters)
limits = quantile(plot.df[,1], probs = seq(0.1,0.9,by=0.1))
##Create Plot
dodge = position_dodge(width=0.5)
p = ggplot(plot.df, aes(x = y,y = x, colour = Parameters)) +
    geom_boxplot(aes(shape = Parameters), outlier.shape = 19, outlier.colour = NULL, outlier.size = 0.8) +
        scale_shape_manual(values = rep(19, 3)) +
            scale_y_continuous(limits = c(0, 1)) …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

4
推荐指数
1
解决办法
590
查看次数

通过R中的geom_text向ggplot添加小于符号"<"

简短的版本:我如何使这个人为的代码绘制一个正确的希腊beta字符和标签字符串的其余部分,空格和小于字符以及格式化为类型的数字?

library("ggplot2")
df<-data.frame(a=1:15,b=6:20)
ggplot(data=df, aes(x=a,y=b)) + geom_point() +
       geom_text(x=5,y=4,label="beta=1.00 p<0.0001", parse=TRUE)
Run Code Online (Sandbox Code Playgroud)

如果我省略",parse = TRUE"参数,字符串效果很好,但不会给我一个真正的希腊测试版.如果我把它放进去,一切都会破裂.


长版本(为什么我找不到重复版本):我终于发现了如何在ggplot2中使用希腊符号?在ggplot上放置希腊字符的方法取决于你放置它们的位置.由于我使用geom_text强制文本字符串到绘图的主体上,我尝试使用表达式(beta)失败了,我最近开始使用上面提到的parse参数.我遇到了如何在ggplot中为geom_text()添加字母数字和希腊字符?,我认为是我的答案,但修复"空间"导致额外的括号弹出,"="替换为逗号,并且丢失了我以前格式化的所有文本数字的格式.

指向使用解析参数的指南的链接,以及如何理解我认为完全不直观的内容对我来说非常有帮助,可能未来的R用户最终会在这里结束.许多搜索都没有结果.

r ggplot2 geom-text

3
推荐指数
1
解决办法
1381
查看次数

在X轴刻度上添加乳胶表达式@ ggplot2

我有这个数据框:

library(ggplot2)
library('latex2exp')

dfvi<-structure(list(rel.imp = c(7.97309042736285, 3.68859054679465, 
-0.672404901177933, -0.56914400358685, 0.461768686793877,-0.393707520847751, 
0.331273538653149, 0.257999910761084, -0.226891321033094, 0.179124365066449
), x.names = c("a", "x", "d", "ft", "ew", "qw", "ccc", "sas", 
"imb", "msf")), row.names = c(NA, -10L), .Names = c("rel.imp", 
"x.names"), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

我使用以下方法进行绘制ggplot2

ggplot(dfvi, aes(x=x.names, y=rel.imp)) +
geom_segment( aes(x=x.names, xend=x.names, y=0, yend=rel.imp),color="grey") +
geom_point( color="orange", size=4) +
scale_y_continuous(breaks=c(-1,seq(0,8,2)))+
scale_x_discrete(labels=c('a'='a','x'='x','d'=TeX('$mode(L_{ij})$'),'ft'=expression('$R_{ij}$'),'ew'=TeX('$Q_{ij}$'),'qw'='qw','ccc'='ccc','sas'='sas','imb'='imb','msf'='msfff'))+
theme_light() + 
theme(
axis.text.x = element_text(angle=90,hjust=1),
panel.grid.major.x = element_blank(),
panel.border = element_blank(),
axis.ticks.x = element_blank()) 
+ xlab("X label") +  ylab("Y label")
Run Code Online (Sandbox Code Playgroud)


这给了我们:

在此处输入图片说明

我想在x轴刻度上使用一些数学符号(例如$ …

plot latex r ggplot2

3
推荐指数
1
解决办法
835
查看次数

使用简单漂亮的代码在绘图中插入公式

Gnu R以非常奇怪的方式发布公式和符号.它经常在这里讨论并在R helppage中提到?plotmath.对于任何曾经LaTeX为R中的简单公式编写代码的人看起来都不可读并且写错了.

是否有更好的方法来注释公式?有这样的函数tex2r("x_2")会生成奇怪的代码吗?

编辑:

我正在寻找一个没有TikZdevice的解决方案,因为TikZdevice仍然非常脆弱,并且printoout看起来并不完全相同.

symbols r

1
推荐指数
1
解决办法
2926
查看次数

具有绝对值条的轴标签

我想在ggplot2中创建一个图,其中x轴是| r |,表示r的绝对值.基于如何在ggplot2中使用希腊符号?我发现我可以使用以下内容来获得希腊符号beta,但我如何获得绝对值条?

p <- p + xlab(expression(beta))

label r ggplot2

1
推荐指数
1
解决办法
1684
查看次数

ggplot2图例中的希腊符号(密度图)

我在ggplot中创建了一个密度图,并试图在图例中使用希腊符号.这就是我试过的:

value1 = 0.8
value2 = 0.8
value3 = 0
greeks <- list(bquote(rho==.(value1)), bquote(rho==.(value2)), bquote(rho==.(value3)))

ggplot(data=df)+
  stat_density(aes(x=R1, colour="rho = -0,6",linetype="rho = -0,6"), 
               adjust=4, lwd=0.5, geom="line", position="identity")+
  stat_density(aes(x=R2, colour="rho = 0,6",linetype="rho = 0,6"), 
               adjust=4, lwd=0.5, geom="line", position="identity")+
  stat_density(aes(x=R3, colour="rho = 0", linetype="rho = 0"), 
               adjust=4, lwd=0.5, geom="line", position="identity")+
  xlim(-1, 1)+
  xlab("Renditen")+
  ylab("Dichte")+
  ggtitle("Renditeverteilung im Heston-Modell")+
  theme(plot.title=element_text(face="bold", size=16, vjust=2, family="Times New Roman"),  
        axis.title.x=element_text(vjust=-1, size=14, family="Times New Roman"),
        axis.title.y=element_text(vjust=-0.25, size=14, family="Times New Roman"), 
        legend.text=element_text(size=14, family="Times New Roman"), legend.title=element_blank(),
        legend.margin=unit(1, "cm"),
        legend.key.height=unit(1, "line"), 
        legend.key.size=unit(0.4, …
Run Code Online (Sandbox Code Playgroud)

symbols r legend ggplot2

0
推荐指数
1
解决办法
2478
查看次数

标签 统计

r ×7

ggplot2 ×6

symbols ×2

geom-text ×1

label ×1

latex ×1

legend ×1

plot ×1