相关疑难解决方法(0)

如何制作一个很好的R可重复的例子

在与同事讨论性能,教学,发送错误报告或在邮件列表上搜索指导时,以及在Stack Overflow上,通常会询问可重复的示例并始终提供帮助.

您有什么建议创建优秀示例的提示?如何以文本格式粘贴中的数据结构?您还应该包含哪些其他信息?

在另外还有其他招数来使用dput(),dump()structure()?你什么时候应该包括library()require()声明?其中保留字应避免一个,此外c,df,data等?

怎样才能成为一位伟大的重复的例子?

r r-faq

2474
推荐指数
23
解决办法
28万
查看次数

ggplot geom_point:如何设置自定义绘图符号的字体?

随着ggplot::geom_point我们能够设置使用绘图符号的任意字符scale_shape_manual.我将举例说明目的:使用三角形在每个单元格中创建一个具有两个值的热图:

require(ggplot2)

data <- data.frame(
    val = rnorm(40),
    grp = c(rep('a', 20), rep('b', 20)),
    x   = rep(letters[1:4], 5),
    y   = rep(letters[1:5], 4)
)

p <- ggplot(data, aes(x = x, y = y, color = val, shape = grp)) +
    geom_point(size = 18) +
    scale_shape_manual(values=c("\u25E4","\u25E2")) +
    theme_minimal() +
    theme(panel.grid = element_blank())

ggsave('triangle-tiles.pdf', device = cairo_pdf, width = 4.1, height = 3.5)
Run Code Online (Sandbox Code Playgroud)

带有geom_point的三角形热图

如果用于符号的字体具有这些特殊字符,则此方法可以正常工作.否则显然是失败的.我知道我们可以明确地定义字体并获得相同的结果geom_text:

require(dplyr)

data <- data %>% mutate(sym = ifelse(grp == 'a', "\u25E4", "\u25E2"))

p …
Run Code Online (Sandbox Code Playgroud)

r heatmap ggplot2 gtable

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

Problems Using grid.edit() in Rscript

I'm having problems using grid.edit() from an Rscript. I'm using grid.edit() to increase the thickness of hollow points in the legend and chart. I took this from this post (Change thickness of a marker in ggplot2). Just looks way better IMO. I know that from source files and Rscripts you can get ggplot objects to plot using print(p), but I need to use grid.edit() so I'm not sure how to fix this. Working example below.

My …

r ggplot2 r-grid

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

标签 统计

r ×3

ggplot2 ×2

gtable ×1

heatmap ×1

r-faq ×1

r-grid ×1