java.graph(file="fuel.frame.spj",format="SPJ")
xlim <- range(fuel.frame$Weight)
ylim <- range(fuel.frame$Mileage)
plot(fuel.frame$Weight, fuel.frame$Mileage, 
	xlab="Weight (pounds)",ylab="Mileage (mpg)",
	xlim=xlim, ylim=ylim,type="n",mgp=c(2.5,1,0))
points(fuel.frame$Weight, fuel.frame$Mileage, col=2)
title("Mileage and weight of vehicles", col=4)
title(sub="Click on a point for further options",col=5)
mtext("Source: Consumer reports, April 1990",side=3, line=0.5)
java.set.page.title("All")
java.set.page.tag("All")

weblinks <- c(
"http://www.epinions.com/auto_Make-1990_Eagle_Summit", # Eagle Summit 4 
"http://www.ford.com", # Ford Escort   4        
"http://www.honda.com", # Ford Festiva 4         
"http://www.mazda.com", # Honda Civic 4          
"http://www.mazda.com", # Mazda Protege 4        
"http://cartalk.cars.com/Survey/Results/Demographics/Comments/Mercury/Tracer-1990.html", # Mercury Tracer 4       
"http://www.nissandriven.com",# Nissan Sentra 4        
"http://www.pontiac.com", # Pontiac LeMans 4       
"http://www.subaru.com",# Subaru Loyale 4        
"http://www.subaru.com",# Subaru Justy 3         
"http://www.toyota.com", # Toyota Corolla 4       
"http://www.toyota.com",# Toyota Tercel 4        
"http://www.volkswagen.com", # Volkswagen Jetta 4     
"http://www.chevrolet.com",# Chevrolet Camaro V8    
"http://www.4adodge.com",# Dodge Daytona          
"http://www.ford.com",# Ford Mustang V8        
"http://www.ford.com",# Ford Probe             
"http://www.honda.com",# Honda Civic CRX Si 4   
"http://www.honda.com",# Honda Prelude Si 4WS 4 
"http://www.nissandriven.com",# Nissan 240SX 4         
"http://www.carreview.com/reviews/sports_cars/product_48302.shtml",# Plymouth Laser         
"http://www.subaru.com",# Subaru XT 4            
"http://www.audi.com", # Audi 80 4              
"http://www.buick.com", # Buick Skylark 4        
"http://www.chevrolet.com",# Chevrolet Beretta 4    
"http://www.chrysler.com", # Chrysler Le Baron V6   
"http://www.ford.com",# Ford Tempo 4           
"http://www.honda.com",# Honda Accord 4         
"http://www.mazda.com",# Mazda 626 4            
"http://www.mitsubishi-motors.co.jp", # Mitsubishi Galant 4    
"http://www.mitsubishi-motors.co.jp",# Mitsubishi Sigma V6    
"http://www.nissandriven.com",# Nissan Stanza 4        
"http://www.oldsmobile.com", # Oldsmobile Calais 4    
"http://www.peugeot.com",# Peugeot 405 4          
"http://www.subaru.com",# Subaru Legacy 4        
"http://www.toyota.com",# Toyota Camry 4         
"http://www.volvo.com",# Volvo 240 4            
"http://www.acura.com",# Acura Legend V6        
"http://www.buick.com",# Buick Century 4        
"http://www.chrysler.com",# Chrysler Le Baron Coupe
"http://www.chrysler.com",# Chrysler New Yorker V6 
"http://carpoint.msn.com/Vip/UsedSingleYear/Eagle/Premier/1990.asp",# Eagle Premier V6       
"http://www.ford.com",# Ford Taurus V6         
"http://www.ford.com",# Ford Thunderbird V6    
"http://www.hyundai.com",# Hyundai Sonata 4       
"http://www.mazda.com",# Mazda 929 V6           
"http://www.nissandriven.com",# Nissan Maxima V6       
"http://www.oldsmobile.com",# Oldsmobile Cutlass Ciera 4   
"http://www.oldsmobile.com",# Oldsmobile Cutlass Supreme V6
"http://www.toyota.com",# Toyota Cressida 6            
"http://www.buick.com",# Buick Le Sabre V6            
"http://www.chevrolet.com",# Chevrolet Caprice V8         
"http://www.ford.com",# Ford LTD Crown Victoria V8   
"http://www.chevrolet.com",# Chevrolet Lumina APV V6      
"http://www.4adodge.com",# Dodge Grand Caravan V6       
"http://www.ford.com",# Ford Aerostar V6             
"http://www.mazda.com",# Mazda MPV V6                 
"http://www.mitsubishi-motors.co.jp",# Mitsubishi Wagon 4           
"http://www.nissandriven.com",# Nissan Axxess 4              
"http://www.nissandriven.com",# Nissan Van 4
)

cars <- row.names(fuel.frame)
types <- as.character(fuel.frame$Type)

for(i in 1:length(cars)) {
  java.identify(fuel.frame$Weight[i], fuel.frame$Mileage[i], 
    labels=paste(cars[i]," (",types[i],")",sep=""),
    actions=java.action.menu(
		java.action.menuitem(
		 action=c(java.action.page(types[i]),
                          java.action.link(weblinks[i],target="_blank")),
                 label=c(paste("Show only",types[i],"vehicles"),
                         paste("Link to vehicle website")))))
}

for(type in unique(types)) {
  idx <- types==type
  plot(fuel.frame$Weight[idx], fuel.frame$Type[idx],
	xlab="Weight (pounds)",ylab="Mileage (mpg)",
	xlim=xlim, ylim=ylim,type="n",mgp=c(2.5,1,0))
  points(fuel.frame$Weight[idx], fuel.frame$Mileage[idx], col=2)
  title(paste("Mileage and weight of",type,"vehicles"), col=4)
  title(sub="Click on a point to jump to manufacturer or opinion website",col=5)
  mtext("Source: Consumer reports, April 1990",side=3, line=0.5)
  java.identify(fuel.frame$Weight[idx], fuel.frame$Mileage[idx], 
    labels=paste(cars[idx]," (",types[idx],")",sep=""),
    actions=java.action.link(weblinks[idx],target="_blank"))
  text(1850,18.5, "[Show all vehicle types]",adj=0,col=5)
  java.identify(1855,18.84,2514,17.98,labels="Show all vehicle types",
	action=java.action.page("All"))
  java.set.page.title(type)
  java.set.page.tag(type)
}
dev.off()