data <- read.csv('input.csv')
print(data)
print(is.data.frame(data))
print(ncol(data))
print(nrow(data))
print(max(data$score))
person = subset(data,score == min(score))
print(person)
write.csv(person,"output.csv")
any(grepl('xlsx',installed.packages()));
library('xlsx')
data = read.xlsx('input.xlsx',sheetIndex = 1)
print(data)
write.xlsx(data,'test.xlsx')
library("rjson")
# Give the input file name to the function.
result <- fromJSON(file = "input.json")
# Print the result.
print(result)
json2dataframe = as.data.frame(result)
print(json2dataframe)
语法
pie(x, labels, radius, main, col, clockwise)
x - 是包含饼图中使用的数值的向量。
labels - 用于描述切片的标签。
radius - 用来表示饼图圆的半径(-1和+1之间的值)。
main - 用来表示图表的标题。
col - 表示调色板。
clockwise - 是一个逻辑值,指示片是顺时针还是逆时针绘制。
# Create data for the graph.
x <- c(11, 30, 39, 20)
labels <- c("70后", "80后", "90后", "00后")
piepercent<- paste(round(100*x/sum(x), 2), "%")
# Give the chart file a name.
png(file = "birth_of_age1.jpg")
# Plot the chart.
pie(x, labels = piepercent, main = "出生年龄段 - 饼状图",col = rainbow(length(x)))
legend("topright", c("70后","80后","90后","00后"), cex = 0.8,
fill = rainbow(length(x)))
# Save the file.
dev.off()
barplot(H,xlab,ylab,main,names.arg,col)
H - 是包含条形图中使用的数值的向量或矩阵。
xlab - 是x轴的标签。
ylab - 是y轴的标签。
main - 是条形图的标题。
names.arg - 是在每个栏下显示的名称向量。
col - 用于给图中的图条给出颜色。
colors <- c("green","orange","brown")
months <- c("一月","二月","三月","四月","五月")
regions <- c("东部地区","西部地区","南部地区")
# Create the matrix of the values.
Values <- matrix(c(2,9,3,11,9,4,8,7,3,12,5,2,8,10,11),nrow = 3,ncol = 5,byrow = TRUE)
# Give the chart file a name.
png(file = "barchart_stacked.png")
# Create the bar chart.
barplot(Values,main = "总收入",names.arg = months,xlab = "月份",ylab = "收入",
col = colors)
# Add the legend to the chart.
legend("topleft", regions, cex = 1.3, fill = colors)
# Save the file.
dev.off()
plot(x, y, main, xlab, ylab, xlim, ylim, axes)
x - 是数据集,其值是水平坐标。
y - 是数据集,其值是垂直坐标。
main - 是图表的标题。
xlab - 是水平轴(y轴)上的标签。
ylab - 是垂直轴(y轴)上的标签。
xlim - 是用于绘制的x的值的极限。
ylim - 是用于绘制的y值的极限。
axes - 指示是否应在绘图上绘制两个轴。
# Get the input values.
input <- mtcars[,c('wt','mpg')]
# Give the chart file a name.
png(file = "scatterplot.png")
# Plot the chart for cars with weight between 2.5 to 5 and mileage between 15 and 30.
plot(x = input$wt,y = input$mpg,
xlab = "重量",
ylab = "里程",
xlim = c(2.5,5),
ylim = c(15,30),
main = "重量 VS 里程"
)
# Save the file.
dev.off()