我有两个R文件,public class RPGFight {
public static void main (String args[]) {
int playerHP = 30;
int boss1HP = 420;
int exp = 0;
System.out.println("You open the chamber door to see what lies beyond.");
System.out.println("A demogorgon jumps out and attacks!");
System.out.println("You deftly pull out your mighty blade and defend youself");
while (boss1HP > 0) {
if (boss1HP > 0) {
int hit1 = (int)(Math.random()*20);
int hit2 = (int)(Math.random()*20);
int hit3 = (int)(Math.random()*20);
int hit4 = (int)(Math.random()*20);
int hit5 = (int)(Math.random()*20);
int hit6 = (int)(Math.random()*20);
int bossDMG = (int)(Math.random()*5);
System.out.println("\nYou hit the demogorgon for " + hit1 + " points of damage");
System.out.println("You hit the demogorgon for " + hit2 + " points of damage");
System.out.println("You hit the demogorgon for " + hit3 + " points of damage");
System.out.println("You hit the demogorgon for " + hit4 + " points of damage");
System.out.println("You hit the demogorgon for " + hit5 + " points of damage");
System.out.println("You hit the demogorgon for " + hit6 + " points of damage");
System.out.println("You have been hit for " + bossDMG + " points of damage");
playerHP -= bossDMG;
boss1HP -= hit1+hit2+hit3+hit4+hit5+hit6;
}
if (boss1HP < 0) {
int expbattle = (int)(Math.random()*126+5);
exp += expbattle;
System.out.println("\nThe demogorgon falls to the floor, lifeless.");
System.out.println("Congratulations! You earned " + expbattle + " points of experience.");
}
}
}
}
和mapio.R
。 main.R
包含一个允许我生成ggplot的函数(plotPointsOnMap)。然后,我将该图传递给mapio.R
,以将其转换为一个图。当我将鼠标悬停在地图上的点上时,在工具提示上会看到重复的信息,如下所示。
如何仅显示一组ggplotly
和lat
而不显示两个?
mapio.R
long
main.R
library(maps)
library(ggmap)
library(ggplot2)
getCoordinatesFromCSV <- function(filePath, latName, longName) {
# Load and read the CSV files
csvData <- read.csv(filePath, header = TRUE, sep = ",")
# Get the longitude and latitude
coordinates <- subset(csvData, select = c(latName, longName))
# Separate the longitude and latitudes
latitude <- coordinates$Latitude
longitude <- coordinates$Longitude
# Return the coordinates as a list
return(list(latitude, longitude))
}
generateGeomPoints <- function(coordinateList, colorLegend) {
# Get the longitude and latitude
latitude <- coordinateList[[1]]
longitude <- coordinateList[[2]]
# Construct a dataframe
dataframe <- data.frame(lat = latitude, lon = longitude)
# Return the constructed point
return(geom_point(data = dataframe, aes(x = lon, y = lat, color = colorLegend)))
}
plotPointsOnMap <- function(location, zoom, mapPoints, labelList) {
# NOTE: The labelList should be in the following format: x-axis
# label, y-axis label, legend name and title of the map.
# Get map of specified location
map <- get_map(location = location, zoom = zoom)
# Dynamically append the layers to the map
mapPlot <- ggmap(map)
for (i in range(1, length(mapPoints))) {
mapPlot <- mapPlot + mapPoints[[i]]
}
# Add axis labels and title
mapPlot <- mapPlot + labs(x = labelList[[2]], y = labelList[[1]]) +
ggtitle(labelList[[4]]) + labs(color = labelList[[3]]) +
theme(plot.title = element_text(hjust = 0.5))
# Return the map plot
return(mapPlot)
}