Reputation: 21
I'm trying to create a treemap using R package treemap similar to the one in a sample from the package.
library(treemap)
data(GNI2010)
treemap(GNI2010,
index=c("iso3"),
vSize="population",
vColor="GNI",
type="value")
Is there any way to add extra labels from columns to display "CHN, 1,35 bln, 20% "
Upvotes: 2
Views: 7969
Reputation: 131
Following lawyeR answer, but adding a detail. If you want to center both labels one above the other, use "\n" as separator in paste function
GNI2010$label <- paste(GNI2010$iso3, GNI2010$population, sep = "\n")
treemap(GNI2010,
index=c("label"),
vSize="population",
vColor="GNI",
type="value")
Upvotes: 6
Reputation: 7664
You could create a new variable, such as "label" below, and with paste
or sprintf
and various format choices for digits, etc., craft whatever label you want. Then use that variable instead of iso3. You will run out of space on the smaller rectangles but there is the force.print.labels
argument to invoke.
Here is a simple example that adds the population.
GNI2010$label <- paste(GNI2010$iso3, GNI2010$population, sep = ", ")
treemap(GNI2010,
index=c("label"),
vSize="population",
vColor="GNI",
type="value")
Upvotes: 10