我有一个如下所示的数据框,当我使用xlsx包将其导出到excel文件时,我真的想删除行名称.
bd <- data.frame(id = 1:200, A = c(rep("One", 100), rep("Two", 100)),
B = c(rep(1,50), rep(0, 50), rep(1, 50), rep(0, 50)))
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用下面的命令,但它将它们保存在excel文件的第一列中.
bd <- data.frame(id = 1:200, A = c(rep("One", 100), rep("Two", 100)),
B = c(rep(1,50), rep(0, 50), rep(1, 50), rep(0, 50)), row.names=NULL)
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我使用的是64位机器,最新版本的R(3.1.2),最新的RStudio版本(0.98.1091)和最新的JAVA(版本8更新31).
我试图要求rJava(rJava_0.9-6),结果是以下错误:
require(xlsx)
Carregando pacotes exigidos: rJava
Error : .onLoad falhou em loadNamespace() para 'rJava', detalhes:
chamada: fun(libname, pkgname)
erro: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Failed with error: ‘package ‘rJava’ could not be loaded’
Run Code Online (Sandbox Code Playgroud)
我已经尝试重新安装Java而没有成功.
有谁知道我该如何解决这个问题?
使用data.table包,是否可以汇总保留输入中未出现的变量组合的数据?
使用plyr包我知道如何使用.drop参数执行此操作,例如:
require(plyr)
df <- data.frame(categories = c(rep("A",3), rep("B",3), rep("C",3)), groups = c(rep(c("X", "Y"),4), "Z"), values = rep(1, 9))
df1 <- ddply(df, c("categories","groups"), .drop = F, summarise, sum = sum(values))
Run Code Online (Sandbox Code Playgroud)
输出:
categories groups sum
1 A X 2
2 A Y 1
3 A Z 0
4 B X 1
5 B Y 2
6 B Z 0
7 C X 1
8 C Y 1
9 C Z 1
Run Code Online (Sandbox Code Playgroud)
在这种情况下,即使其总和为0,我也会保留所有组/类别组合.
在这种情况下,一切都很好:
x <- 1:10
y <- x^3
plot(x, y)
identify(x, y)
Run Code Online (Sandbox Code Playgroud)
但是,使用qplot有一些麻烦:
x <- 1:10
y <- x^3
qplot(x, y)
identify(x, y)
Run Code Online (Sandbox Code Playgroud)
有没有人知道类似的命令或其他方式来标记ggplot2图中的特定点?
我正在使用ggmap和ggplot包绘制圣保罗地图中两个不同数据框的经度和纬度坐标,并希望手动标记每个图例层:
更新:我编辑了下面的代码以完全可重现(我使用的是地理编码功能而不是get_map).
更新:我想在不合并数据框的情况下这样做.
require(ggmap)
sp <- get_map('sao paulo', zoom=11, color='bw')
restaurants <- data.frame(lon=c(-46.73147, -46.65389, -46.67610),
lat=c(-23.57462, -23.56360, -23.53748))
suppliers <- data.frame(lon=c(-46.70819,-46.68155, -46.74376),
lat=c(-23.53382, -23.53942, -23.56630))
ggmap(sp)+geom_point(data=restaurants, aes(x=lon, y=lat),color='blue',size=4)+geom_point(data=suppliers, aes(x=lon, y=lat), color='red', size=4)
Run Code Online (Sandbox Code Playgroud)

我已经看了几个问题并尝试了不同的方法但没有成功.有谁知道如何插入图例并将蓝点标记为餐馆,将红点标记为供应商?
我有一个像这样的数据框:
x <- data.frame(time = c('1', '2', '3'), perc = c(0.2, 0.4, 0.6, 0.3, 0.55, 0.69, 0.2, 0.22, 0.35), type=c(rep('a', 3), rep('b', 3), rep('c', 3)))
Run Code Online (Sandbox Code Playgroud)
并希望做一个这样的情节(如下),但使用这些不同的颜色c('#0023a0', '#f9a635', '#bebec0'):
ggplot(x, aes(time, perc, group=type, colour=type, shape=type)) + geom_point(size=4) + geom_line(size=1)
Run Code Online (Sandbox Code Playgroud)

使用我已经尝试了不同的方式scale_colour_hue,scale_shape_discrete和scale_fill_manual,但没有成功.