小编ily*_*lya的帖子

改变emacs ess中的缩进

我想知道如何更改emacs ess中的缩进.我通常喜欢默认的(ess-set-style'C++'安静)但有时候格式非常奇怪.例如,这就是我想要的,如果它不是函数的一部分,这将是默认格式:

  ggplot(data = overtime.by.month,
         aes(x="",
             y=Percent,
             fill = Overtime)) +
  geom_bar(width = 1) +
  xlab('') +
  ylab(sub.txt) +
  labs(title = title.txt) +
  facet_wrap(~Year.Month) +
  geom_text(aes(y = txt.pos, label = Per.txt)) +
  coord_polar(theta = "y") +
  scale_fill_manual(values = c('green', 'red')) +
  theme(axis.ticks = element_blank(),
        axis.text.y = element_blank(),
        axis.text.x = element_blank())
Run Code Online (Sandbox Code Playgroud)

这是我用当前缩进样式得到的,如果我把它放在函数内部.

a <- function(){

    a <- ggplot(data = overtime.by.month,
                aes(x="",
                    y=Percent,
                    fill = Overtime)) +
                        geom_bar(width = 1) +
                            xlab('') +
                                ylab(sub.txt) +
                                    labs(title = title.txt) +
                                        facet_wrap(~Year.Month) +
                                            geom_text(aes(y …
Run Code Online (Sandbox Code Playgroud)

emacs r ess

19
推荐指数
2
解决办法
3221
查看次数

将图像插入图表区域外的ggplot

是否可以将图像添加到ggplot图表中,该图表将位于图表区域之外?

我知道可以使用annotate_raster和annotate_custom将图像添加到图表中,但是它们都会在图表中添加图像.我需要在图表上方的右上角添加公司徽标 - 在标题级别.

使用annotate_custom添加图像的示例:将图像 插入ggplot2

更新:根据user1317221_G的建议,我可以将图像放在外面.

library(png)
library(grid)
library(ggplot2)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))

g <- rasterGrob(img, interpolate=TRUE)
plt <- qplot(1:10, 1:10, geom="blank") +
      opts(title = 'Title') + 
      geom_point() 
plt2 <- plt + annotation_custom(g, xmin=9, xmax=10, ymin=10.5, ymax=11.25)

gt <- ggplot_gtable(ggplot_build(plt2))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)
Run Code Online (Sandbox Code Playgroud)

我想自动放置图像 - 自动确定xmin/xmax和ymin/ymax.使用传统图形我可以调用par('usr')并获取图表参数,但这不适用于ggplot图表.有没有一种简单的方法来确定ggplot中的绘图区域?例如,获取plt的大小并将限制值插入plt2

UPDATE2:如果使用分面,此方法也不起作用.例如,我想在标题级别的右角放置徽标,如下图所示,如果我使用上面的方法,我会收到错误.

d <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + 
     xlim(0, 2) + 
     stat_binhex(na.rm = TRUE) + 
     labs(title = 'Title') +
     theme(aspect.ratio = 1) + 
     facet_wrap(~ color, scales = …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

如何使用指定的列顺序保存对R中的数据框进行排序?

假设我有一个data.frame

x <- data.frame(a = c('A','A','A','A','A', 'C','C','C','C', 'B','B','B'),
                b = c('a','c','a','a','c', 'd', 'e','e','d', 'b','b','b'),
                c = c( 7,  3,  2,  4,  5,   3,   1,  1,  5,   5,  2,  3),
                stringsAsFactors = FALSE)

> x
   a b c
1  A a 7
2  A c 3
3  A a 2
4  A a 4
5  A c 5
6  C d 3
7  C e 1
8  C e 1
9  C d 5
10 B b 5
11 B b …
Run Code Online (Sandbox Code Playgroud)

sorting r dataframe

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

如何使用星期日开始scale_x_date周开始

我正在创建一个每周时间序列图表,周应该从周日开始.当我指定scale_x_date(breaks = date_breaks('1周'))网格线和标签在星期一开始时,结果看起来稍微偏离.我怎样才能强制ggplot scale_x_date周在周日开始

这是我的代码示例

library(ggplot2)
library(scales)

data.set <- structure(list(week.start = structure(c(15732, 15739,
                           15746, 15753, 15760, 15767, 15774, 15781,
                           15788, 15795, 15802, 15809 ), class =
                           "Date"), overtime.avg = c(2.8,
                           2.85666666666667, 2.18333333333333,
                           2.44666666666667, 2.04833333333333,
                           2.45833333333333, 2.12833333333333,
                           1.81666666666667, 1.82166666666667,
                           1.54333333333333, 2.09166666666667,
                           0.970833333333333)), .Names =
                           c("week.start", "overtime.avg"), row.names
                           = 29733:29744, class = "data.frame")

ggplot(data = data.set,
       aes(x = week.start,
           y = overtime.avg)) +
    geom_line() +
    geom_point() +
    scale_x_date(breaks = date_breaks("1 week"),
                 labels = date_format(format = "%Y-%m-%d"))
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

使用R Markdown将徽标插入投影仪演示文稿中

我试图使用Rmarkdown在beamer presenation中插入徽标,看起来大小控件\logo{\includegraphics[height=1cm,width=3cm]{logo.png}}不起作用,无论我放在那里的值,图像总是相同的大小.手动修改图像以外的任何建议?

---
title: "Presentation"
author: "Author"
output:
  beamer_presentation:
    includes:
      in_header: mystyle.tex

---

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting
syntax for authoring HTML, PDF, and MS Word documents. For more
details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that
includes both content as well as the output of any embedded R code
chunks within the document.

## Slide with Bullets …
Run Code Online (Sandbox Code Playgroud)

markdown r beamer

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

R地狱的第一圈.0.1!= 0.3/3

可能重复:
R中的数字比较难度

大家好,

根据"R Inferno"论文.我现在正处于R地狱的第一圈.这是异教徒期望0.1 == 0.3/3的地方.Paper建议all.equal在这种情况下使用函数,但是我需要检查"> ="或"<="条件.目前他们的例子失败了:

> .1 >= .3/3
[1] TRUE
> .1 <= .3/3
[1] FALSE
Run Code Online (Sandbox Code Playgroud)

是否有类似于all.equal的函数来检查不等式?

谢谢,

伊利亚

r inequalities

5
推荐指数
3
解决办法
1184
查看次数

更新后ggplot2堆积条形图顺序坏了

我刚刚更新了我的ggplot2包,并开始使用条形图获取以下警告消息:

将变量映射到y并使用stat ="bin".使用stat ="bin",它将尝试将y值设置为每个组中的个案数.这可能会导致意外行为,并且在将来的ggplot2版本中将不允许这样做.如果您希望y表示案例计数,请使用stat ="bin"并且不要将变量映射到y.如果您希望y表示数据中的值,请使用stat ="identity".

我在我的代码中添加了stat ='identity'.现在,堆积条形图中的订单是错误的(订单由因子级别定义).我真的不知道如何解决它.我现在可以暂时离开它 - 但是警告信息说将来不允许这样做,所以我现在想解决它.这有什么工作吗?

这是数据和代码示例:

data.set <- structure(list(Date = structure(c(15675, 15676, 15677, 15678, 
15679, 15680, 15681, 15682, 15683, 15684, 15685, 15686, 15687, 
15688, 15689, 15690, 15691, 15692, 15693, 15694, 15695, 15696, 
15697, 15698, 15699, 15700, 15701, 15702, 15703, 15704, 15705, 
15675, 15676, 15677, 15678, 15679, 15680, 15681, 15682, 15683, 
15684, 15685, 15686, 15687, 15688, 15689, 15690, 15691, 15692, 
15693, 15694, 15695, 15696, 15697, 15698, 15699, 15700, 15701, 
15702, 15703, 15704, 15705, 15675, 15676, 15677, …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

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

在Ubuntu上网本上运行R需要图形设备大小的帮助

在ubuntu上网本上运行R时,我对图形设备的大小有小问题.上网本的屏幕尺寸相对较小(1024 x 576),所以当我在R中创建一个图表简单说

plot(sin)
Run Code Online (Sandbox Code Playgroud)

图表大于我的屏幕尺寸.我必须手动调整大小.

在ubuntu论坛上发布的解决方案由于某种原因不起作用.有谁知道如何修理它?

谢谢!

ubuntu r

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

图表上的多色文本

问候,

我需要在我的图表上显示多色文本

early <- 30
ontime <- 70
late <- 25

txt <- paste(early, ontime, late, sep='/')
plot(1:2, type='n')
text(1.5, 1.5, txt)
Run Code Online (Sandbox Code Playgroud)

我需要早期,正常时间,晚期txt的值,分别为蓝色,绿色和红色.

我在标题中找到了关于多色文本的帖子,但是我无法使其适应我的问题 http://blog.revolutionanalytics.com/2009/01/multicolor-text-in-r.html

谢谢您的帮助

r

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

标签 统计

r ×9

ggplot2 ×3

beamer ×1

dataframe ×1

emacs ×1

ess ×1

inequalities ×1

markdown ×1

sorting ×1

ubuntu ×1