ChartJS – Different color per data point

In updating to version 2.2.2 of ChartJS, I found that the accepted answer no longer works. The datasets will take an array holding styling information for the properties. In this case: var pointBackgroundColors = []; var myChart = new Chart($(‘#myChart’).get(0).getContext(‘2d’), { type: ‘line’, data: { datasets: [ { data: dataPoints, pointBackgroundColor: pointBackgroundColors } ] } … Read more

Combining Bar and Line chart (double axis) in ggplot2

First, scale Rate by Rate*max(df$Response) and modify the 0.9 scale of Response text. Second, include a second axis via scale_y_continuous(sec.axis=…): ggplot(df) + geom_bar(aes(x=Year, y=Response),stat=”identity”, fill=”tan1″, colour=”sienna3″)+ geom_line(aes(x=Year, y=Rate*max(df$Response)),stat=”identity”)+ geom_text(aes(label=Rate, x=Year, y=Rate*max(df$Response)), colour=”black”)+ geom_text(aes(label=Response, x=Year, y=0.95*Response), colour=”black”)+ scale_y_continuous(sec.axis = sec_axis(~./max(df$Response))) Which yields:

JFreeChart line chart with text at each point

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 … Read more

Missing legend with ggplot2 and geom_line

put colour inside the aes like this: d<-data.frame(x=1:5, y1=1:5, y2=2:6) ggplot(d, aes(x)) + geom_line(aes(y=y1, colour=”1″)) + geom_line(aes(y=y2, colour=”2″)) + scale_colour_manual(values=c(“red”, “blue”)) but I recommend this way: d2 <- melt(d, id=”x”) ggplot(d2, aes(x, value, colour=variable)) + geom_line() + scale_colour_manual(values=c(“red”, “blue”))