如何在ggplot2 :: geom_step()中将线居中,类似于highcharter

时间:2019-05-02 15:00:45

标签: r ggplot2 highcharts r-highcharter

对于我的绘图,我希望<script> export default { name: 'Camera', data() { return { video: {}, canvas: {}, captures: [] } }, mounted() { this.video = this.$refs.video; if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ video: true }).then(stream => { video.srcObject = stream; video.play(); video.onplay = function () { }; this.video.play(); }); } }, methods: { capture() { this.canvas = this.$refs.canvas; var context = this.canvas.getContext("2d").drawImage(this.video, 0, 0, 640, 480); this.captures.push(canvas.toDataURL("image/webp")); } } } </script>线的对齐方式以我的点为中心,而不是向左对齐

<style> #camera { text-align: center; color: #2c3e50; } #video { background-color: #000000; } #canvas { display: none; } li { display: inline; padding: 5px; } </style>中有一个名为if len(xk) != len(pk): raise ValueError("xk and pk need to have the same length.") #if not np.allclose(np.sum(pk), 1): #raise ValueError("The sum of provided pk is not 1.") 的选项。看看我的jsfiddle是我在ggplot2::geom_step()中的样子。

highcharter::hc_add_series(type = "line")

reprex package(v0.2.1)于2019-05-02创建

1 个答案:

答案 0 :(得分:1)

您可以使用position = position_nudge(x = -0.5)

我调整了您的lcl和ucl值,以使更改更易于查看。

my_data <- 
  data.frame(
    x = as.Date(c("2015-06-01", "2015-07-01", "2015-08-01", "2015-09-01",
          "2015-10-01", "2015-11-01", "2015-12-01", "2016-01-01")),
    y = c(35, 41, 40, 45, 56, 54, 60, 57),
    cl = c(37, 37, 37, 37, 59, 59, 59, 59),
    ucl = c(48, 47, 42, 47, 70, 69, 68, 68),
    lcl = c(26, 27, 30, 27, 48, 49, 50, 49)
  ) 

ggplot(my_data, aes(x = x, y = y, group = 1)) +
  geom_line() + 
  geom_point() + 
  geom_step(aes(y = cl), position = position_nudge(x = -15)) +
  geom_step(aes(y = ucl), position = position_nudge(x = -15)) +
  geom_step(aes(y = lcl), position = position_nudge(x = -15))

enter image description here