我正在尝试为ggplot获取一个自定义图例,数据来自两个独立的数据框.请参阅下面的最小可重复示例.
我想要完成的是有一个描述色带填充,黑色线条和红色线条的图例.
require(ggplot2)
x=seq(1,10,length=100)
data=data.frame(x,dnorm(x,mean=6.5,sd=1))
names(data)=c('x','new.data')
x.ribbon=seq(1,10,length=20)
ribbon=data.frame(x.ribbon,
dnorm(x.ribbon,mean=5,sd=1)+.01,
dnorm(x.ribbon,mean=5,sd=1)-.01,
dnorm(x.ribbon,mean=5,sd=1))
names(ribbon)=c('x.ribbon','max','min','avg')
ggplot()+geom_ribbon(data=ribbon,aes(ymin=min,ymax=max,x=x.ribbon),fill='lightgreen')+
geom_line(data=ribbon,aes(x=x.ribbon,y=avg),color='black')+
geom_line(data=data,aes(x=x,y=new.data),color='red')+
xlab('x')+ylab('density')
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用prcomp和绘制主成分分析ggbiplot.我正在获取单位圆外的数据值,并且在调用之前无法重新调整数据prcomp,我可以将数据约束到单位圆.
data(wine)
require(ggbiplot)
wine.pca=prcomp(wine[,1:3],scale.=TRUE)
ggbiplot(wine.pca,obs.scale = 1,
var.scale=1,groups=wine.class,ellipse=TRUE,circle=TRUE)
Run Code Online (Sandbox Code Playgroud)
我在调用之前通过减去平均值并除以标准偏差来尝试缩放prcomp:
wine2=wine[,1:3]
mean=apply(wine2,2,mean)
sd=apply(wine2,2,mean)
for(i in 1:ncol(wine2)){
wine2[,i]=(wine2[,i]-mean[i])/sd[i]
}
wine2.pca=prcomp(wine2,scale.=TRUE)
ggbiplot(wine2.pca,obs.scale=1,
var.scale=1,groups=wine.class,ellipse=TRUE,circle=TRUE)
Run Code Online (Sandbox Code Playgroud)
ggbiplot 包安装如下:
require(devtools)
install_github('ggbiplot','vqv')
Run Code Online (Sandbox Code Playgroud)
输出任一代码块:

根据@Brian Hanson在下面的评论,我正在添加一个反映我想要获得的输出的附加图像.

我正在尝试使用dpdownr的rmarkdown v2输入选择来选择要报告的某些列.然后,将在给定nls()函数的公式中使用所选列来确定某些常量C的值.
我的代码如下:
---
title: "Test"
author: "Author"
date: "Wednesday, June 18, 2014"
output: html_document
runtime: shiny
---
```{r, echo=TRUE}
require(dplyr)
#Some sample random data in a data.frame:
test=data.frame(A=runif(n=10),V=runif(n=10),N=runif(n=10))
#Input box to choose desired column
inputPanel(
selectInput('sample.choice', label = 'Choose Columns',
choices = c('V Sample'='V',
'N Sample'='N'),
selected='N')
)
#Make a reactive data.frame to be used with the nls function
test2=reactive(test%.%select(A,input$sample.choice))
#Display the data.frame
renderDataTable(test2())
#Use nls solver to determine a constant with a given formula:
c.fit=reactive(nls(A ~ I(C*input$sample.choice),data=test2(),start=list(C=1)))
renderText(summary(c.fit())) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用geom_point()在ggplot2中获得一个具有映射到x,y,颜色和形状的变量的图,并避开颜色的位置而不是形状。
x=tibble(Color=c(rep('A',12),rep('B',12),rep('C',12)),
Shape=rep(c(rep('A',3),rep('B',3),rep('C',3),rep('D',3)),3),
xVar=rep(c('A','B','C'),12),
Value=rnorm(36))
ggplot(x,aes(xVar,Value,color=Color,shape=Shape))+
geom_point(position=position_dodge(width=.5))
Run Code Online (Sandbox Code Playgroud)
是否可以将闪避位置限制为仅一种美学?我已经搜索过文档和堆栈溢出,但是还没有发现任何东西。