小编J.C*_*Con的帖子

当 parse=TRUE 时将 geom_text 更改为粗体

我正在注释分面图以包含上标,但无法将文本设为粗体。我意识到这与expression在 plot 调用之外创建一个,然后指定parse=TRUE. 可能有一个非常简单的解决方案,但到目前为止我尝试过的任何方法都没有奏效,包括使用bquote()and bold()。谢谢

library(ggplot2)

data(iris)

rsq<-c(.3,.6,.75)
pos<-c(5,6,7)
Species<-levels(iris$Species)

big_data<-as.data.frame(cbind(pos, rsq))
big_data$Species<-Species

lab <- paste("r^2 == ", round(big_data$rsq,2))

ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
  facet_wrap(~Species,scales='free_x')+
  geom_point(size=3,show.legend = F) +
  geom_text(aes(x=pos,y=1,label=as.character(lab)),parse=TRUE,data=big_data,fontface='bold')
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

plot r ggplot2 geom-text

8
推荐指数
3
解决办法
2万
查看次数

小提琴图形状中的堆积条形图

也许这是一个愚蠢的想法,或者也许这是一个脑电波。我有 4 个不同物种的脂质类数据集。数据是成比例的,总和是 1000。我想可视化每个物种中每个类别的比例差异。通常,堆叠条形图是这里的方法,但有几个类,并且由于只有底层类共享基线(见下文),因此变得无法解释。传统叠放吧

这似乎是一群坏人中的最佳选择,饼图和甜甜圈图简直就是被嘲笑。然后我受到了这个创作的启发对称的、类似小提琴的情节直方图?,它创建了一种堆叠分布的小提琴图(见下文)。 堆叠分布小提琴

我想知道是否可以以某种方式将其转换为堆叠的小提琴,这样每个部分都代表一个完整的变量。就我的数据而言,物种的 A 和 D 在 TAG 段周围将是“胖”的,而在 STEROL 段则是“更瘦”。这样比例被水平描绘,并且总是有一个共同的基线。想法?

数据:

structure(list(Sample = c("A", "A", "A", "B", "B", "B", "C", 
"C", "C", "D", "D"), WAX = c(83.7179798600773, 317.364310355766, 
20.0147496567679, 93.0194886619568, 78.7886829173726, 79.3445694220837, 
91.0020522660375, 88.1542855137005, 78.3313314713951, 78.4449591023115, 
236.150030864875), TAG = c(67.4640254081232, 313.243238213156, 
451.287867136276, 76.308508343969, 40.127554151831, 91.1910102221636, 
61.658394708941, 104.617259648364, 60.7502685224869, 80.8373642262043, 
485.88633863193), FFA = c(41.0963382465756, 149.264019576272, 
129.672579626868, 51.049208042632, 13.7282635713804, 30.0088572108344, 
47.8878116348504, 47.9564218319094, 30.3836532949481, 34.8474205480686, 
10.9218910757234), `DAG1,2` = c(140.35876401479, 42.4556176551009, 
0, 0, 144.993393432366, 136.722412691012, 0, …
Run Code Online (Sandbox Code Playgroud)

plot r data-visualization

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

没有使用Shiny的链接图

我创建了一个shiny应用程序来显示大型数据集的相关热图.按下热图贴图后,将显示相应的散点图.

但是,我需要制作其中几个应用程序,这超出了我的发布限制shinyapps.io.我的公司不愿意升级到付费计划.我尝试使用其他方法发布应用程序,如RInno无效(我认为应用程序太复杂了?).

如果有人能告诉我如何plotly单独生产同样的东西而不是shiny,我会永远感激.我相信crosstalk可能是将热图贴图链接到散点图的路径?

谢谢

这里的例子.

library(plotly)
library(shiny)

# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)

ui <- fluidPage(
  mainPanel(
    plotlyOutput("heat"),
    plotlyOutput("scatterplot")
  ),
  verbatimTextOutput("selection")
)

server <- function(input, output, session) {
  output$heat <- renderPlotly({
    plot_ly(x = nms, y = nms, z = correlation, 
            key = correlation, type = "heatmap", source = "heatplot") %>%
      layout(xaxis = list(title = ""), 
             yaxis = list(title = ""))
  }) …
Run Code Online (Sandbox Code Playgroud)

interactive r shiny plotly ggplotly

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

在 ggplot x 轴上显示所有日期值 - R

在下面的小数据集中,我想在 x 轴上绘制日期值。我希望标记数据框中存在的所有日期刻度。目前它只标记 3 个随机刻度。我可以将列更改为一个因子,但作为日期意味着 x 轴根据点之间的时间间隔间隔开。到目前为止,我能找到的唯一答案是希望每个月或至少等间隔时间显示的问题。我只想显示数据集中的值。谢谢

数据:

dput(melt)
structure(list(Sample = structure(c(16023, 16023, 16027, 16027, 
16031, 16031, 16035, 16035, 16038, 16038, 16044, 16044, 16023, 
16023, 16027, 16027, 16031, 16031, 16035, 16035, 16038, 16038, 
16044, 16044), class = "Date"), Treatment = structure(c(1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L), .Label = c("T1", "T5"), class = "factor"), 
    variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, …
Run Code Online (Sandbox Code Playgroud)

r date ggplot2

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

从flextable中的字符串动态设置colnames

flextable帮助的细节描述了将新的标头,对每一个新的头名手动键入每个现有的头名,如下所示:

library(flextable)
ft_1 <- regulartable(head(iris))
ft_1 <- set_header_labels(ft_1, Sepal.Length = "SL",
                          Sepal.Width = "SW", Petal.Length = "PL",
                          Petal.Width = "PW"
)
ft_1
Run Code Online (Sandbox Code Playgroud)

我怎样才能从一个字符串中添加所有新的标题名称,例如

(names2<-c('SL','SW','PL','PW','SPECIES'))
[1] "SL"      "SW"      "PL"      "PW"      "SPECIES"
Run Code Online (Sandbox Code Playgroud)

?

到目前为止,我已经管理了一个非常hacky的解决方案:

names(names2)<-names(ft_1$header$dataset[1,])

ft_1$header$dataset[1,]<-names2
Run Code Online (Sandbox Code Playgroud)

r flextable officer

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

使用dplyr-R检查组中的字符是否全部相等

在下面的数据框中,如何将前两列分组并检查第四列中的所有值是否相同?如果它们相同,我想用代替它们''

在此示例中,组组合'embryonated + protein''Hatching + Lipid'是仅有的两个字母都不全的组a

df

         Stage variable Temperature letters       Mean
30 Embryonated Moisture          30       a  808.70882
31 Embryonated      NFE          20       a   53.28806
32 Embryonated      NFE          25       a   45.38572
33 Embryonated      NFE          30       a   84.56113
34 Embryonated  Protein          20      ab  118.53608
35 Embryonated  Protein          25       b  127.29849
36 Embryonated  Protein          30       a   84.55175
37    Hatching      Ash          20       a   16.95345
38    Hatching      Ash          25       a   14.54980
39    Hatching      Ash          30       a   13.38510 …
Run Code Online (Sandbox Code Playgroud)

r dataframe dplyr

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

RInno 在 RStudio 中使用 Shiny 的详细示例

我需要制作多个 Shiny 应用程序,在shiny.io. 所以我正在尝试使用RInno. 我知道这很荒谬,但是RInno初学者教程对我来说似乎太少了(他们确实称其为“最小示例”)。我根本无法弄清楚我要做什么。在本教程中,使用预加载的“示例”应用程序进行演示。

# If you don't have development tools, install them
install.packages("devtools"); require(devtools)

# Use install_github to get RInno
devtools::install_github("ficonsulting/RInno",  build_vignettes = TRUE)

# Require Package
require(RInno)

# Use RInno to get Inno Setup
RInno::install_inno()

# Example app included with RInno package
example_app(wd = getwd())

# Build an installer
create_app(app_name = "Your appname", app_dir = "app")
compile_iss()
Run Code Online (Sandbox Code Playgroud)

当我在 RStudio 中运行它时,一个名为的文件夹app出现在我的工作目录中。我打开它以找到以下内容(屏幕截图):

在此处输入图片说明

现在我该怎么做?我尝试打开“您的应用程序名称”并按照设置说明进行操作(单击下一步>下一步>下一步>>>完成)。这会在我的桌面上放置一个名为“您的应用程序名称”的快捷方式。我打开这个但得到错误:

在此处输入图片说明

难道我做错了什么?这是一个错误吗?从第一个屏幕截图打开html文件夹中的app文件夹会显示我认为是示例的绘图的 html。这很适合我自己的需要。但是,当我尝试使用类似的东西启动我自己的现有应用程序时 …

inno-setup r shiny

5
推荐指数
0
解决办法
2808
查看次数

从Shiny,Plotly-R中提取所有点击事件图

在以下shiny应用程序中,该plotly程序包用于创建交互式关联热图.单击单个图块时,将显示相应的散点图.然后,可以通过单击下载单个散点图download plot as png.但有没有办法一次下载所有可能的散点图而不必点击每个单独的瓷砖并保存每个单独的瓷砖?谢谢

library(plotly)
library(shiny)

# compute a correlation matrix
correlation <- round(cor(mtcars), 3)
nms <- names(mtcars)

ui <- fluidPage(
  mainPanel(
    plotlyOutput("heat"),
    plotlyOutput("scatterplot")
  ),
  verbatimTextOutput("selection")
)

server <- function(input, output, session) {
  output$heat <- renderPlotly({
    plot_ly(x = nms, y = nms, z = correlation, 
            key = correlation, type = "heatmap", source = "heatplot") %>%
      layout(xaxis = list(title = ""), 
             yaxis = list(title = ""))
  })

  output$selection <- renderPrint({
    s <- event_data("plotly_click")
    if (length(s) …
Run Code Online (Sandbox Code Playgroud)

r shiny plotly r-plotly

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

与 geom_signif 函数的多重比较,R

该包ggsignif对于快速、轻松地指示ggplot图表中的显着比较非常有用。但是,该comparisons调用需要手动键入要比较的每对值。

例如。

library(ggplot2)
library(ggsignif)

data(iris)

ggplot(iris, aes(x=Species, y=Sepal.Length)) + 
  geom_boxplot() +
  geom_signif(comparisons = list(c("versicolor", "virginica"),c('versicolor','setosa')), 
              map_signif_level=TRUE)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我想知道如何通过立即引用所有可能的组合来避免这种情况?例如,expand.grid(x = levels(iris$Species), y = levels(iris$Species)),给出所有组合

           x          y
1     setosa     setosa
2 versicolor     setosa
3  virginica     setosa
4     setosa versicolor
5 versicolor versicolor
6  virginica versicolor
7     setosa  virginica
8 versicolor  virginica
9  virginica  virginica
Run Code Online (Sandbox Code Playgroud)

但如何让这个被接受geom_signif(comparisons=...呢?

软件包信息可在此处获取https://cran.r-project.org/web/packages/ggsignif/index.html

statistics r graph ggplot2 pairwise

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

强制 ggplot 刻度从一年第一天、一月第一天等开始

我正在寻找一种方法来强制 a 上的日期标签从ggplot(看似)逻辑时间开始。我已经多次遇到这个问题,但我当前的问题是我希望在“我01/01/yyyy 的数据是一个大型数据集”上进行中断,其中包含 POSIXct 日期列、要在“流量”列中绘制的数据以及“站点”列中的多个站点名称。

library(ggplot2)
library(scales) 
ggplot(AllFlowData, aes(x=Date, y = Flow, colour = Site))+geom_line()+
scale_x_datetime(date_breaks = "1 year", expand =c(0,0),labels=date_format("%Y"))
Run Code Online (Sandbox Code Playgroud)

我可以强制每年都有休息时间,如果没有labels=date_format("%Y")(每年 01/01 开始),它们看起来还不错,但如果我包括labels=date_format("%Y")(因为有 10 年的数据,所以有点混乱),日期标签会移至 ~11 月,尽管我的数据从 01/01/1990 开始,但 1989 是第一个标签。

过去,我在不同的时间步长上多次遇到过这个问题,例如想要将其强制到该月的 1 号或每天的午夜而不是白天。有没有通用的方法来做到这一点?

我已经研究过在 ggplot2 (scale_x_date) 中创建特定的日期范围,但我不想对我的中断进行硬编码,因为我有相当多的图与不同的日期范围有关。

谢谢

datetime r date ggplot2 posixct

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