linechart

Group data and plot multiple lines

女生的网名这么多〃 提交于 2019-11-26 20:10:50
问题 I'd like to plot multiple lines in R for this dataset: (x = Year, y = Value) School_ID Year Value A 1998 5 B 1998 10 C 1999 15 A 2000 7 B 2005 15 Each school has data for different years. I'd like to have one line for each school. 回答1: Let's create some data: dd = data.frame(School_ID = c("A", "B", "C", "A", "B"), Year = c(1998, 1998, 1999, 2000, 2005), Value = c(5, 10, 15, 7, 15)) Then to create a plot in base graphics, we create an initial plot of one group: plot(dd$Year[dd$School_ID=="A"],

Google Chart: How to draw the vertical axis for LineChart?

≡放荡痞女 提交于 2019-11-26 18:27:56
问题 I want to draw a Google's line chart in my web page! Here is my js code: function drawVisualization() { // Create and populate the data table. var data = google.visualization.arrayToDataTable([ ['x', 'Cats', 'Blanket 1'], ['A', 1, 10], ['B', 2, 5], ['C', 4, 12], ['D', 8, 5] ]); var options = { curveType: 'function', lineWidth: 2, hAxis: { baselineColor: 'red', textStyle: {color: '#000', fontName: 'Arial', fontSize: 10}, gridlines: { color: '#f3f3f3', count: 5} }, vAxis: { baseline: 0,

Using d3 to shade area between two lines

谁都会走 提交于 2019-11-26 18:19:23
问题 So I have a chart plotting traffic vs. date and rate vs. date. I'm trying to shade the area between the two lines. However, I want to shade it a different color depending on which line is higher. The following works without that last requirement: var area = d3.svg.area() .x0(function(d) { return x(d3.time.format("%m/%d/%Y").parse(d.original.date)); }) .x1(function(d) { return x(d3.time.format("%m/%d/%Y").parse(d.original.date)); }) .y0(function(d) { return y(parseInt(d.original.traffic)); })

Missing legend with ggplot2 and geom_line

拥有回忆 提交于 2019-11-26 16:38:00
How does one get a legend to display when plotting lines in ggplot? I've been trying all evening but have been unsuccessful. p <- ggplot(output, aes(lambda), legend=TRUE) + geom_line(aes(y=train.err), colour="red", label="r") + geom_line(aes(y=test.err), colour="blue", label="b") + geom_line(aes(y=data.err), colour="green", label="g") print(p) Where output is a dataframe with the following structure: 'data.frame': 2101 obs. of 4 variables: $ lambda : num 3.06e-07 3.09e-07 3.12e-07 3.15e-07 3.18e-07 ... $ train.err: num 0.415 0.415 0.415 0.415 0.415 ... $ test.err : num 0.373 0.373 0.373 0.373

JFreeChart line chart with text at each point

◇◆丶佛笑我妖孽 提交于 2019-11-26 13:50:57
I would like put text over each point I plotted in a line chart. This is what I can do: And this is what I need (names of point are in green): The StandardXYItemLabelGenerator should work; there's an example here . Addendum: The labels you can see in the picture are in a separate string array. Such labels may be incorporated in the XYDataset , as shown in LabeledXYDataset below. Because none of the features of StandardXYItemLabelGenerator are used, a custom implementation of XYItemLabelGenerator is sufficient. The XYItemRenderer controls the color, size and relative position of the labels.

Combining Bar and Line chart (double axis) in ggplot2

你离开我真会死。 提交于 2019-11-26 12:40:45
问题 I have double-y-axis chart made in Excel . In Excel it requires only basic skills. What I\'d like to do is to replicate this chart using the ggplot2 library in R . I have already done this, but I need to plot Response on 2nd-y-axis . I enclose reproducible code I\'ve used: #Data generation Year <- c(2014, 2015, 2016) Response <- c(1000, 1100, 1200) Rate <- c(0.75, 0.42, 0.80) df <- data.frame(Year, Response, Rate) #Chart library(ggplot2) ggplot(df) + geom_bar(aes(x=Year, y=Response),stat=\

ChartJS - Different color per data point

有些话、适合烂在心里 提交于 2019-11-26 08:23:19
问题 Is there a way to set a different color to a datapoint in a Line Chart if its above a certain value? I found this example for dxChart - https://stackoverflow.com/a/24928967/949195 - and now looking for something similar for ChartJS 回答1: For chartjs 2.0 see this following answer. Original answer below. Good question regarding ChartJS. I've been wanting to do a similar thing. i.e dynamically change the point colour to a different colour. Have you tried this below. I just tried it and it worked

Missing legend with ggplot2 and geom_line

瘦欲@ 提交于 2019-11-26 05:36:12
问题 How does one get a legend to display when plotting lines in ggplot? I\'ve been trying all evening but have been unsuccessful. p <- ggplot(output, aes(lambda), legend=TRUE) + geom_line(aes(y=train.err), colour=\"red\", label=\"r\") + geom_line(aes(y=test.err), colour=\"blue\", label=\"b\") + geom_line(aes(y=data.err), colour=\"green\", label=\"g\") print(p) Where output is a dataframe with the following structure: \'data.frame\': 2101 obs. of 4 variables: $ lambda : num 3.06e-07 3.09e-07 3.12e

JFreeChart line chart with text at each point

与世无争的帅哥 提交于 2019-11-26 03:44:41
问题 I would like put text over each point I plotted in a line chart. This is what I can do: And this is what I need (names of point are in green): 回答1: The StandardXYItemLabelGenerator should work; there's an example here. Addendum: The labels you can see in the picture are in a separate string array. Such labels may be incorporated in the XYDataset , as shown in LabeledXYDataset below. Because none of the features of StandardXYItemLabelGenerator are used, a custom implementation of