I'd like to do some plots of historical event data on a reverse log
scale, started, say at the year 2000 and going
backwards in time, with tick marks spaced according to log(2000-year).
For example, see:
http://euclid.psych.yorku.ca/SCS/Gallery/images/log-timeline.gif
As an example, I'd like to create a density plot of such data with the
horizontal axis reverse-logged,
a transformation of this image:
http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/mileyears1.gif
Some initial code to do a standard density plot looks like this:
mileyears <- read.csv("mileyears3.csv", skip=1,
col.names=c("key","year","where","add","junk"))
mileyears <- mileyears[,2:4]
years <- mileyears$year
years1500 <- years[years>1500]
dens <- density(years1500, from=1500, to=1990)
plot(dens)
rug(years1500)
I could calculate log(2000-year), but I'm not sure how to do the
plotting, do some minor tick marks
and label the major ones, say at 100 year intervals.
thanks,
-Michael
--
Michael Friendly Email: friendly at yorku.ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA
On 7/6/2005 3:36 PM, Michael Friendly wrote:> I'd like to do some plots of historical event data on a reverse log > scale, started, say at the year 2000 and going > backwards in time, with tick marks spaced according to log(2000-year). > For example, see: > > http://euclid.psych.yorku.ca/SCS/Gallery/images/log-timeline.gif > > As an example, I'd like to create a density plot of such data with the > horizontal axis reverse-logged, > a transformation of this image: > http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/mileyears1.gif > > Some initial code to do a standard density plot looks like this: > > mileyears <- read.csv("mileyears3.csv", skip=1, > col.names=c("key","year","where","add","junk")) > mileyears <- mileyears[,2:4] > > years <- mileyears$year > years1500 <- years[years>1500] > dens <- density(years1500, from=1500, to=1990) > plot(dens) > rug(years1500) > > I could calculate log(2000-year), but I'm not sure how to do the > plotting, do some minor tick marks > and label the major ones, say at 100 year intervals.I think you'll have to do everything explicitly. That is, something like this: years1500 <- runif(500, 1500, 1990) # some fake data x <- log(2000-years1500) from <- log(2000-1990) to <- log(2000-1500) plot(density(x, from=from, to=to), axes=F) rug(x) labels <- pretty(years1500) labels <- labels[labels<2000] axis(1, labels, at=log(2000-labels)) minorticks <- pretty(years1500, n=20) minorticks <- minorticks[minorticks<2000] axis(1, labels=FALSE, at=log(2000-minorticks), tcl=-0.25) axis(2) box() Duncan Murdoch
Do you want to move year 2000 to Inf? How about a cube root
transformation instead:
year <- seq(0, 4000, 100)
y2000.3 <- (sign(year-2000)*
abs(year-2000)^(1/3))
plot(y2000.3, year, axes=FALSE)
axis(1, y2000.3, year)
axis(2)
Of course, one should package the transformation in a function and
more carefully select the tick marks, but a little study of the help
pages for the functions in this example should suffice for that.
spencer graves
Michael Friendly wrote:
> I'd like to do some plots of historical event data on a reverse log
> scale, started, say at the year 2000 and going
> backwards in time, with tick marks spaced according to log(2000-year).
> For example, see:
>
> http://euclid.psych.yorku.ca/SCS/Gallery/images/log-timeline.gif
>
> As an example, I'd like to create a density plot of such data with the
> horizontal axis reverse-logged,
> a transformation of this image:
> http://euclid.psych.yorku.ca/SCS/Gallery/milestone/Test/mileyears1.gif
>
> Some initial code to do a standard density plot looks like this:
>
> mileyears <- read.csv("mileyears3.csv", skip=1,
>
col.names=c("key","year","where","add","junk"))
> mileyears <- mileyears[,2:4]
>
> years <- mileyears$year
> years1500 <- years[years>1500]
> dens <- density(years1500, from=1500, to=1990)
> plot(dens)
> rug(years1500)
>
> I could calculate log(2000-year), but I'm not sure how to do the
> plotting, do some minor tick marks
> and label the major ones, say at 100 year intervals.
>
> thanks,
> -Michael
>
>
>
>
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
Thanks to all who replied, particularly Duncan Murdoch, whose solution I
adopted.
It thought it might be of interest to some to see the results and
compare these ways
of representing the distribution of historical events over time.
The events are the items I record on my site, Milestones in the History
of Data
Visualization,
http://www.math.yorku.ca/SCS/Gallery/milestones
Here is the subset of events post 1500:
subset<-
c(1530, 1533, 1545, 1550, 1556, 1562, 1569, 1570, 1572, 1581,
1605, 1603, 1603, 1614, 1617, 1624, 1623, 1626, 1632, 1637, 1644,
1646, 1654, 1654, 1657, 1663, 1662, 1666, 1669, 1671, 1686, 1686,
1687, 1693, 1693, 1701, 1710, 1711, 1712, 1724, 1727, 1745, 1741,
1748, 1752, 1752, 1752, 1753, 1765, 1760, 1763, 1765, 1765, 1781,
1776, 1778, 1779, 1782, 1782, 1782, 1785, 1786, 1787, 1794, 1795,
1796, 1798, 1798, 1800, 1800, 1801, 1801, 1809, 1811, 1817, 1819,
1825, 1821, 1822, 1825, 1827, 1828, 1832, 1830, 1832, 1833, 1833,
1833, 1833, 1836, 1836, 1837, 1838, 1839, 1839, 1843, 1843, 1843,
1844, 1846, 1846, 1851, 1852, 1853, 1855, 1857, 1857, 1857, 1861,
1861, 1863, 1868, 1869, 1869, 1869, 1872, 1872, 1872, 1872, 1873,
1874, 1874, 1874, 1874, 1875, 1875, 1877, 1877, 1877, 1878, 1878,
1879, 1879, 1889, 1880, 1882, 1882, 1883, 1884, 1884, 1884, 1884,
1884, 1885, 1885, 1885, 1888, 1892, 1895, 1896, 1899, 1901, 1904,
1905, 1910, 1910, 1911, 1912, 1913, 1913, 1913, 1913, 1914, 1914,
1915, 1920, 1916, 1917, 1925, 1919, 1920, 1923, 1923, 1924, 1925,
1926, 1929, 1928, 1928, 1929, 1930, 1931, 1933, 1942, 1937, 1939,
1944, 1944, 1957, 1957, 1958, 1962, 1965, 1966, 1965, 1967, 1968,
1969, 1969, 1969, 1971, 1971, 1972, 1973, 1973, 1974, 1974, 1974,
1974, 1975, 1975, 1975, 1975, 1975, 1976, 1977, 1977, 1978, 1978,
1979, 1981, 1981, 1981, 1982, 1982, 1983, 1983, 1985, 1985, 1987,
1988, 1988, 1989, 1989, 1990, 1990, 1990, 1990, 1990, 1991, 1991,
1993, 1992, 1994, 1996, 1999)
>
The standard density plot, labeled according to periods of time
shows quite interpretable trends,
# standard plot
plot(density(subset, from=1500, to=1990, bw="sj"),
main="Milestones: Time course of development",
xlab="Year")
ref <-c(1600, 1700, 1800, 1850, 1900, 1950, 1975)
abline(v= ref, lty=3, col="blue")
labx<-c(1550, 1650, 1750, 1825, 1875, 1925, 1962, 1987)
laby<- 0.003 + 0.0003 * c(0, 1, 2, 3, 5, 3, 5, 2)
txt1 <-c("Early maps",
"Measurement\n& theory",
"New graphic\nforms",
"Modern\nage",
"Golden Age",
"Modern dark\nages",
"Re-birth",
"Hi-D Vis")
text(labx, laby, labels=txt1, cex=1.25, xpd=TRUE)
rug(subset, quiet=TRUE)
The idea of a reverse log scale for representing events in time was
suggested by
\whom{Heinz}{Von Foerster} in 1930, and this (below) produces the
corresponding
plot; you might imagine this as a view of the density of events standing at
the year 2000, and looking back at time through a log-scaled telescope.
I wanted to see what this looked like, but I'm not sure it is of
particularly
greater use here, except to suggest alternative ways to represent historical
time. Any comments?
# reverse log plot
rlogyear <- -log(2000-subset)
#from <- -log(2000-1990)
#to <- -log(2000-start)
# need to swap, so from < to for density
to <- -log(2000-1990)
from <- -log(2000-start)
plot(density(rlogyear, from=from, to=to, bw="sj"), axes=F,
main="Milestones: Time course of development",
xlab="Year (reverse log scale)")
rug(rlogyear, quiet=TRUE)
labels <- pretty(subset)
labels <- c(labels[labels<2000], 1950, 1975, 1990)
axis(1, labels, at=-log(2000-labels))
minorticks <- pretty(subset, n=30)
minorticks <- minorticks[minorticks<2000]
axis(1, labels=FALSE, at=-log(2000-minorticks), tcl=-0.25)
axis(2)
ref <-c(1600, 1700, 1800, 1850, 1900, 1950, 1975)
abline(v= -log(2000-ref), lty=3, col="blue")
labx<-c(1550, 1650, 1750, 1825, 1875, 1925, 1962, 1987)
laby<- 0.35 + 0.03 * c(-1, .5, 2.2, 4, 1.6, .3, -1, -2)
text(-log(2000-labx), laby, labels=txt1, cex=1.2, xpd=TRUE)
box()
Final question:
How can I reduce the interline space in multiline strings?
From ?par, I tried lheight:
> text(-log(2000-labx), laby, labels=txt1, cex=1.2, xpd=TRUE, lheight=.8)
NULL
Warning message:
parameter "lheight" couldn't be set in high-level plot() function
>
--
Michael Friendly Email: friendly at yorku.ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT M3J 1P3 CANADA