I'm trying to plot a bar chart with multiple bars on each point of the x axis, and a line chart on the same graph showing the ratio of the two columns over the top. I'm getting the bars to render fine, but getting the error "line 22: warning: Skipping data file with no valid points" for the line plot.
I'm guessing this is due to setting the plot style to histogram, but I'm not sure. Do I need to change it again to do the line plot? I've seen some examples online of single bars with a line plot over them, but I'm not sure about doing a clustered bar chart and a line. Can anyone help out please?
EDITED:
I've stripped my code and data file down from what I was using in my original post, to hopefully improve clarity and get rid of any excess data that might be messing things up.
The code I'm now using is as follows;
set terminal png size 800,500 enhanced font "Times,12"
set output 'test.png'
red = "#FF0000"; green = "#00FF00"; blue = "#0000FF"; skyblue = "#87CEEB";
set key right top
set yrange [0:0.2]
set ylabel "Percentage"
set y2range [0:1.0]
set y2label "Ratio"
set style data histogram
set style histogram cluster gap 1
set style fill solid
set boxwidth 0.9
set xtics format ""
set ytics
set y2tics
set grid ytics
set title "Some title"
plot "mydata.dat" using ($2/100.0):xtic(1) title "Group 1" linecolor rgb green, \
'' using ($3/100.0) title "Group 2" linecolor rgb blue , \
'' using 1:($2/$3) with lines axis x1y2
And the mydata.dat file looks like this;
# File of data
A 12.3 17.6
B 11.7 16.2
C 11.1 15.9
D 8.3 12.1
E 9.2 10.5
But I'm still getting a error message "myfile.gnuplot", line 22: warning: Skipping data file with no valid points
This is again an example why it is important and helpful to always add data to a question.
You are trying to use column 1 as x coordinate. Since column 1 are characters, this won't work. Instead, use pseudocolumn 0, which is basically the line index (0-based), check help pseudocolumns
. The histogram style is implicitly using pseudocolumn 0 as x-coordinate as well.
Script:
### add a line plot to a histogram
reset session
$Data <<EOD
# File of data
A 12.3 17.6
B 11.7 16.2
C 11.1 15.9
D 8.3 12.1
E 9.2 10.5
EOD
red = "#FF0000"; green = "#00FF00"; blue = "#0000FF"; skyblue = "#87CEEB";
set key right top out
set yrange [0:0.2]
set ylabel "Percentage"
set y2range [0:1.0]
set y2label "Ratio" tc "red"
set style data histogram
set style histogram cluster gap 1
set style fill solid
set boxwidth 0.9
set xtics format ""
set ytics nomirror
set y2tics tc "red"
set grid ytics
set title "Some title"
plot $Data u ($2/100.0):xtic(1) title "Group 1" lc rgb green, \
'' u ($3/100.0) title "Group 2" lc rgb blue , \
'' u 0:($2/$3) w lp pt 7 lc "red" axis x1y2 title "ratio"
### end of script
Result: