datastorm-open / rAmCharts

API for Amcharts
48 stars 16 forks source link

Add points in amPlot ? #58

Closed AerisJu closed 7 years ago

AerisJu commented 7 years ago

Hi ,

I developed an application with R Shiny and to display my graphics I use rAmCharts. I would like to include points (with x and y values) in an AmPlots. For example with R, I display a graph with plot function and I add points with points function. I would like to do the same thing with rAmCharts. I try with amLines but it doesn't work because I don't have the same number of values. Do you have a solutions? I work on Windows 7 and R 3.2.5

Thank you !

Djaiff commented 7 years ago

Hi !

Could you tell me more about what you wanna do ? If your series don't have the same number of values, how do you wan't to display the "x" axis ?

We didn't include this feature since we have to manipulate the dataProvider, so the performances could be affected in case of a large dataset. But, actually we can do this with amcharts and so with rAmCharts by defining the chart without 'am' function, it's quite easy:

xlab <- paste0("Value", 1:150)
y1 <- sample(c(rnorm(100), rep(NA, 50)))
y2 <- rnorm(150)
dataProvider <- data.frame(xlab = xlab, y1 = y1, y2 = y2)

amSerialChart(categoryField = "xlab", precision = 2) %>%
  setDataProvider(dataProvider = dataProvider, keepNA = TRUE) %>%
  addGraph(valueField = "y1", lineColor = "darkblue") %>%
  addGraph(valueField = "y2", lineColor = "grey") %>%
  setChartCursor()

The trick is the argument keepNA in the dataProvider.

I hope it will help, Don't hesitate to give your feedback !

AerisJu commented 7 years ago

Hi !

It's not exactly what I want to do. I would like to do this with rAmCharts : screenshot This is graph with dataset (blue dots) and some points are highlighted ​​to another color (red). This graph is generated with R code. I don't know how to add red points on graph with rAmCharts.

Thank you for your answers.

Djaiff commented 7 years ago

I think you don't need to add points in other color, but rather change the color for them. Is this can be enough ?

xlab <- 1:150
y <- rnorm(150)
color <- numeric(150L)
color[c(100, 110, 125)] <- "red"
dataProvider <- data.frame(xlab, y, color)

amSerialChart(categoryField = "xlab", dataProvider = dataProvider, precision = 2) %>%
  addGraph(valueField = "y", colorField = "color", bullet = "round", lineAlpha = 0)
AerisJu commented 7 years ago

Perfect, it's easier than I thought ! But I search the zoom option for amSerialChart, I don't find this.

Djaiff commented 7 years ago

Cool, for zooming you can try to pipe setChartCursor() or setChartScrollbar() (without argument)

AerisJu commented 7 years ago

It's perfect, thank you!