A21 Simple Line Chart - cimat/data-visualization-patterns GitHub Wiki
Line charts display the quantitative value of an observed object over a continuous interval.In most cases, this interval is a time span, and the graph describes how the object’s variable changes over this time interval. The line chart is a widely used diagram type, and due to its familiar structure easy to grasp. Besides the individual values themselves the most significant information that can be derived from it is the gradient of the curve, which provides information about the intensity of the attribute’s change over time. Also, minimum and maximum values can be easily identified from such a representation (Behrens, 2008).
Use the simple line chart to display pairs of numerical values derived from tabular data. As a specific feature of line charts, there is basically no free choice of which variable is assigned to which axis in the coordinate system. Instead, one of the two variables should be scaled on an interval, meaning it consists of a regular, continuous series of numbers. This variable is called the independent variable, and usually referred to as the x-variable. Each of these independent variables in the table has a certain y-value assigned to it: The dependent variable (Behrens, 2008).
With the independent variable applied to the horizontal axis in the coordinate grid, the chart consists of a set of points with regular distances to their respective neighbors. The points are then connected by a line that represents a continuous development of the value, even if only punctual values are known from the table. The accuracy of the graph depends on the density of points in the coordinate grid (Behrens, 2008).
Create a two-dimensional Cartesian coordinate system. Label and subdivide the two axes according to the variables’ scales and units with the independent variable assigned to the x-axis. For each row in the table (i.e. for each pair of variates), draw a point at the corresponding coordinates in the coordinate pane. Connect the points with each other through a continuous line from left to right. The result of this process is a line or curve that reflects an approximation of the dependent variable’s development over the interval of the independent variable. The smaller the distance between two neighboring points, the higher the graph’s accuracy (Behrens, 2008).
Set within a Cartesian coordinate system, line charts are one of the most common and most widely used diagram types. The expressive power of this type of infographic lies in the user’s ability to interpret the development of a magnitude over an interval, such as time, by merely looking at the way the graph line “moves” from left to right. Even without detailed information at hand, a quick glance at the “big picture“ provides valuable insight to the data already.
A 2.2 Multiset Line Chart
A 2.4 Sparklines
Simple line Chart is type of graph showing a line ascending and / or descending, line chart regularly shows the tendency of a data set against other data (regularly) against a time interval.
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
import matplotlib.pyplot as plt
from datos import data
d=data('mtcars')
t =d.am
s =d.gear
plt.xlim(0,1.2)
plt.plot(t,s)
plt.xlabel('Transmission (0 = automatic, 1 = manual)')
plt.ylabel('Number of forward gears')
plt.title('Motor Trend Car Road Tests')
plt.grid(True)
plt.show()
import matplotlib.pyplot as plt
import seaborn as sns
from datos import data
d=data('mtcars')
t =d.am
s =d.gear
sns.set_style("whitegrid")
plt.plot(t,s)
plt.xlabel('Transmission (0 = automatic, 1 = manual)')
plt.ylabel('Number of forward gears')
plt.title('Motor Trend Car Road Tests')
plt.show()
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
from datos import data
d=data("mtcars")
app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('Simple Line Chart Example')
view.resize(800,600)
p1 = l.addPlot(title="Motor Trend Car Road Tests")
p1.plot(d.am,d.gear)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore,
'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
Simple Line Chart pattern is very easy to implement on R, insomuch as R have a package called graphics in which can to make simple line chart, package graphics is recomended but there are more packages that are not default on R that can be implemented to make Simple Line Chart Pattern.
Then it shows an example of R pattern implementation.
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 ## Code example
cars <- (mtcars$wt)
plot(cars, type="o", col="blue")
title(main="Cars", col.main="blue", font.main=4)
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
library(ggplot2)
ggplot(data=mtcars, aes(x=mtcars$wt, y=mtcars$mpg))+
geom_line()+
geom_point()
library(lattice)
panel.spline <- function(x, y) {
panel.xyplot(x, y)
panel.loess(x, y)
}
attach(mtcars)
## The following object is masked from package:ggplot2:
##
## mpg
xyplot(mpg~wt, scales=list(cex=2, col="red"),
panel=panel.spline)