A22 Multiset Line Chart - cimat/data-visualization-patterns GitHub Wiki
In most cases, a line chart is used to display the behavior of one single value over an interval. However, there are situations in which it is important to let the user directly compare several variables and their development over the same interval. Instead of drawing several charts next to each other with each one displaying one single graph, create a single coordinate system that fosters the requirements of each variable within the same system. The Multiple Line Chart pattern incorporates several simple line charts within the same coordinate base.
Use this type of diagram to display several quantitative variables and their development over a shared regular interval, for instance time. The variables you want to display may express different quantities, so that the y-axis might adopt more than one scale. But they all share the same reference variable, and here should lie within the same interval. If not, you have to choose appropriate interval boundaries to foster all variables you want to display.
Create a two-dimensional Cartesian coordinate system. Label and subdivide the x-axis according to the variable expressing the interval, while the y-axis carries the labels for those variables you want to display. If your dataset contains variables of different scale and unit, attach several scales to the y-axis, and make them clearly distinguishable. For each data item, draw a point at the corresponding locations in the coordinate pane. Connect points that belong to the same set with each other through a continuous line from left to right. The result of this process is a set of lines or curves that reflects an approximation of the dependent variables’ developments over the examined interval. The smaller the distance between two neighboring points, the higher the graph’s accuracy.
Obviously, the advantages of the simple line chart apply to the multivariate extension as well. Furthermore, the user is given a powerful tool to directly compare different variables within the same chart. And last but not least, combining several variables within one single chart can save you a substantial amount of space compared to drawing a separate diagram for each variable.
A 2.1 Simple Line Chart
A 2.3 Stacked Area Chart
A multiple line chart is a graphic in which show multiple data series and allows a more graphic visual comparison between the different data groups.
For this example it will be used Data Set called mtcars, this data set is the R default data set, to use this data set, was used a Python module called rpy2, which is used to use data sets of R in python. This data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
list of Modules that are required for implementation
Matplotlib Seaborn PyQtGraph
from datos import data
import matplotlib.pyplot as plt
d=data('mtcars')
carb=d.carb
wt= d.wt
plt.ylim(0,11)
plt.title('Motor Trend Car Road Tests Carb and wt')
plt.plot(carb , '--',wt, '--')
plt.show()
\
import matplotlib.pyplot as plt
import seaborn as sns
from datos import data
d=data('mtcars')
t=d.carb
s= d.wt
sns.set_style("whitegrid")
plt.plot(t,'--',s,'--')
plt.title('Motor Trend Car Road Tests Carb and wt')
plt.show()
\
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
from datos import data
d=data('mtcars')
t=d.carb
s= d.wt
plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: Legend')
plt.addLegend()
c1 = plt.plot(t, pen='r',name='red plot')
c2 = plt.plot(s, pen='g', fillLevel=0, name='green plot')
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore,
'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
A multiple line chart is a graphic in which show multiple data series and allows a more graphic visual comparison between the different data groups.
For this example it will be used Data Set called mtcars, this data set is the R default data set this data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
head(mtcars)
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
Graphics - default package on R Ggplot2 Lattice
carb <- mtcars$carb
cyl <- mtcars$cyl
plot(carb, type="o", col="blue", ylim=c(0,10))
lines(cyl, type="o", pch=22, lty=2, col="red")
title(main="Mtcars", col.main="Blue", font.main=4)
library(ggplot2)
df2 <- mtcars
ggplot(data=df2, aes(x=mpg, y=hp, group=gear)) +
geom_line()+
geom_point()
library(lattice)
L = mtcars$am == 0
Camaro=mtcars["Camaro Z28",]
Datsun=mtcars["Datsun 710",]
x= 1:11
df <- data.frame(Camaro = Camaro, Datsun = Datsun, x = x)
## Warning in data.frame(Camaro = Camaro, Datsun = Datsun, x = x): row names
## were found from a short variable and have been discarded
xyplot(Camaro + Datsun ~ x, data = df, type = "o", auto.key=TRUE)