[R] plotting on a reverse log scale

Sundar Dorai-Raj sundar.dorai-raj at pdf.com
Thu Jul 7 21:00:23 CEST 2005



Michael Friendly wrote:
> 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
>  >
> 

(sorry, it send on the wrong reply)

Try:

olpar <- par(lheight = 0.8, no.readonly = TRUE)
text(-log(2000-labx), laby, labels=txt1, cex=1.2, xpd=TRUE)
par(olpar)

HTH,

--sundar




More information about the R-help mailing list