小编jon*_*nie的帖子

ggplot2:从x轴日期删除周末和假日的空格

在ggplot2中绘制库存数据时遇到问题,并且x轴包含周末和假日的间隙.这篇文章非常有帮助,但在尝试使用有序因子时遇到了各种各样的问题.

library(xts)
library(grid)
library(dplyr)
library(scales)
library(bdscale)
library(ggplot2)
library(quantmod)

getSymbols("SPY", from = Sys.Date() - 1460, to = Sys.Date(), adjust = TRUE, auto.assign = TRUE)

input <- data.frame(SPY["2015/"])
names(input) <- c("Open", "High", "Low", "Close", "Volume", "Adjusted")

# i've tried changing rownames() to index(), and the plot looks good, but the x-axis is inaccurate
# i've also tried as.factor()
xaxis <- as.Date(rownames(input)) 
input$xaxis <- xaxis

p <- ggplot(input)
p <- p + geom_segment(aes(x = xaxis, xend = xaxis, y = Low, …
Run Code Online (Sandbox Code Playgroud)

r date ggplot2

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

Quantmod振荡器

利用quantmod包中的chartSeries函数,我想修改RSI振荡器.给定一个包含OHLC价格数据的xts对象,这是我正在使用的调用:

chartSeries(plot_report[, 1:4],
        name        = substr(ticker, 1, nchar(ticker) - 4),
        theme       = chartTheme('white.mono', grid.col = NA),
        TA          = c(addRSI(n = 14, maType = "SMA")),
        type        = "line",
        bar.type    = 'ohlc',
        major.ticks = 'months',
        show.grid   = FALSE,
        log.scale   = TRUE)
Run Code Online (Sandbox Code Playgroud)

生成此图表: 在此输入图像描述

我有四个问题:

  1. 如何将蓝色的默认颜色更改为其他颜色?我试过了:c(addRSI(n = 14,maType ="SMA",col ="black")).但是,我得到"未使用的参数"错误.

  2. 我可以在振荡器面板中绘制水平线吗?传统RSI在y轴值为70时具有水平红线,在y轴值为30时具有水平绿线以指示超买/超卖水平.

  3. 是否可以将另一个计算绘制为图表下方的振荡器线?我想要一些专有的振荡器,而不是RSI或TTR包中的任何指示器.

  4. 我如何参与改进quantmod图表功能; 这个项目是否得到积极维护?

charts r quantmod

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

重新绘制饼图,里面有值标签

使用 recharts 库,我很想创建一个这样的甜甜圈图:https ://apexcharts.com/javascript-chart-demos/pie-charts/simple-donut/

具体来说,值标签位于饼图段内。我在文档中找到的唯一示例使用自定义渲染标签,但我希望使用新标签组件,这会更容易:http ://recharts.org/en-US/examples/PieChartWithCustomizedLabel

按照这个例子,这是我能得到的最接近的,但标签没有居中: 在此处输入图片说明

这是新的 Label 组件文档。我试过了: <Label position="inside />

这是 customLabelRendering 的代码:

const RADIAN = Math.PI / 180;
const renderCustomizedLabel = ({
  cx, cy, midAngle, innerRadius, outerRadius, percent, index,
}) => {
   const radius = innerRadius + (outerRadius - innerRadius) * 0.5;
  const x = cx + radius * Math.cos(-midAngle * RADIAN);
  const y = cy + radius * Math.sin(-midAngle * RADIAN);

  return (
    <text x={x} y={y} fill="white" textAnchor={x > cx ? 'start' : …
Run Code Online (Sandbox Code Playgroud)

reactjs recharts

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

VScode:如何更改 HTML 打开和关闭标签的颜色

如何更改 VScode 中 HTML 打开/关闭标签的颜色以匹配下图?我曾尝试使用Highlight Matching Tag扩展程序和以下设置,但这仅适用于选择 (onFocus) 标签。我希望打开标签的实际字体颜色与所有关闭标签不同。谢谢!

  "highlight-matching-tag.styles": {
    "opening": {
      "name": {
        "custom": {
          "color": "#007fff",
        }
      }
    },
    "closing": {
      "name": {
        "custom": {
          "color": "#F02931"
        }
      }
    }
  },
Run Code Online (Sandbox Code Playgroud)

期望输出

html syntax-highlighting jsx visual-studio-code

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

检查向量并输出单数TRUE或FALSE值

我使用以下命令检查数据集中的重复日期:

duplicateTest <- duplicated(index(closePricesClean))
Run Code Online (Sandbox Code Playgroud)

对于每个不重复的日期,此输出为"FALSE".因此,如果closePricesClean有500个观察值,则duplicateTest将返回500个"TRUE"或"FALSE"值的列表.我想要的是,如果整个向量为"FALSE",则返回单个"FALSE"值,如果列表包含一个"TRUE"值,则返回"TRUE".

我需要构造一个if语句吗?还是有一个我不知道的功能?

boolean r duplicates

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

将函数应用于指定范围; 变化率

可能重复:
计算R中的移动平均值

我在R中编写了一个变化率函数,定义如下:

rateChange <- function(x) ((last(x)-first(x))/first(x))*100
Run Code Online (Sandbox Code Playgroud)

它适用于各种日期范围,例如5天,10天,200天等的变化率.但是,我现在需要在每天之间应用此功能.例如,为了确定5天的变化率,需要过去6次数据观察.

以下是Excel中的示例,为清楚起见,我正在尝试重现"更改率"列:

数据

谢谢!

r apply

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