当使用管道操作符%>%与包,如dplyr,ggvis,dycharts,等,我该怎么办了一步条件?例如;
step_1 %>%
step_2 %>%
if(condition)
step_3
Run Code Online (Sandbox Code Playgroud)
这些方法似乎不起作用:
step_1 %>%
step_2
if(condition) %>% step_3
step_1 %>%
step_2 %>%
if(condition) step_3
Run Code Online (Sandbox Code Playgroud)
有很长的路要走:
if(condition)
{
step_1 %>%
step_2
}else{
step_1 %>%
step_2 %>%
step_3
}
Run Code Online (Sandbox Code Playgroud)
没有所有冗余,有没有更好的方法?
我想将Python用于科学应用程序,经过一些研究决定我将使用Anaconda,因为它捆绑了大量的软件包并conda install通过cmd 添加新的模块很容易.
我更喜欢使用64位版本以获得更好的RAM使用和效率,但也需要32位版本,因为有些库是32位.同样,我更喜欢使用Python 3.5,因为这是未来和事情的发展方向.但是大量的库仍然是2.7,这意味着我需要两者.
我必须安装4个版本的Anaconda(64bit 2.7,64bit 3.5,32bit 2.7,64bit 3.5).每个版本大约380MB.我的目标是使用Jupyter笔记本和Spyder作为IDE.我必须在需要时在版本之间切换.我有相互矛盾的库,路径问题和各种奇怪的问题.
所以,我打算从头开始做一个干净的安装.我想知道是否有更明智的方法来处理这个问题.如果重要的话,我现在使用Windows 7 64位.
一旦定义了标签,如何定义标签外/下的内容?或者,我如何结束标签内容?
我已经计划了这样的布局:
title
content above tabbed region.
tab1 tab2
-------------------
tab content 1
-------------------
content below tabbed region
Run Code Online (Sandbox Code Playgroud)
在rmarkdown将是
## title {.tabset .tabset-fade}
content above tabbed region.
### tab 1
tab content 1
### tab 2
tab content 2
content below tabbed region.
Run Code Online (Sandbox Code Playgroud)
但是,content below tabbed region.作为tab2的一部分出现.如何在标签外定义?
也许我可能在下面的内容中有进一步的标题.因此,一个相关的问题是如何定义哪些标题是标签的一部分以及哪些标题不是?
是否可以在R图例中使用字符和数字的混合作为绘图符号?
plot(x=c(2,4,8),y=c(5,4,2),pch=16)
points(x=c(3,5),y=c(2,4),pch="+")
legend(7,4.5,pch=c("+",16),legend=c("A","B")) #This is the problem
Run Code Online (Sandbox Code Playgroud) 我有一张桌子,我想用ggplot2制作一个情节,到目前为止我还没有成功.我准备了一个看起来像这样的简化表
df1<-data.frame(Loc=c(rep("L1",5),rep("L2",3),rep("L3",4)),
Type=c(rep("T1",3),rep("T2",2),"T1","T2","T2","T1","T1","T2","T2"),
y2009=rep("A",12),y2010=c("A","B","A","A","A","A","B","B","A","A","B","B"),
y2011=c("B","B","B","A","B",rep("B",4),"A","B","B"))
df1
Run Code Online (Sandbox Code Playgroud)
Loc有3个位置.每个位置有2种类型的样本T1或T2.他们从2009年开始作为A,随着时间的推移,有些人成为B.因此,到2011年,有很多B.
这是我到目前为止的数字
ggplot(df1,aes(x=Type)) + geom_bar()+facet_grid(~Loc)
ggplot(df1,aes(x=y2009,fill=Type)) + geom_bar(position="dodge")+facet_grid(~Loc)
Run Code Online (Sandbox Code Playgroud)

我不太确定如何从三个因素中得到计数.
我想要一个类似于下面的数字,我粗略地在油漆中起草.facet是位置,我只为Loc1制作了条形图.

是否有可能在PCA图上测试2个已知组之间聚类的重要性?测试它们的接近程度或扩散量(方差)以及簇之间的重叠量等.
如何更改图例区域和面板之间的间距ggplot2 2.2.0?
library(ggplot2)
library(dplyr)
library(tidyr)
dfr <- data.frame(x=factor(1:20),y1=runif(n=20)) %>%
mutate(y2=1-y1) %>%
gather(variable,value,-x)
ggplot(dfr,aes(x=x,y=value,fill=variable))+
geom_bar(stat="identity")+
theme(legend.position="top",
legend.justification="right")
Run Code Online (Sandbox Code Playgroud)
改变legend.margin或legend.box.margin似乎没有做任何事情.
ggplot(dfr,aes(x=x,y=value,fill=variable))+
geom_bar(stat="identity")+
theme(legend.position="top",
legend.justification="right",
legend.margin=margin(0,0,0,0),
legend.box.margin=margin(0,0,0,0))
Run Code Online (Sandbox Code Playgroud) 是否可以滚动井板或柱?
我这里有一个简单的ui方案.
shinyUI(
fluidPage(
sidebarLayout(
sidebarPanel(
wellPanel(),
wellPanel()
),
mainPanel(
fluidRow(
column(3,
wellPanel()
)
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
我想让一些wellPanels(里面的表格)可滚动.
我尝试在'sidebarPanel(')下面添加下面这段代码,但这使得我的整个侧边栏会滚动.我希望将'wellPanel'或'column'设置为可滚动.
tags$head(tags$style(
type = 'text/css',
'form-group { max-height: 600px; overflow-y: auto; }')
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个包含几百个节点和边的图.断开连接的子图分离出来并很好地解决,但子图中的节点重叠并且不能很好地解析.我尝试了几种布局算法,并尝试更改布局算法中的相关参数(例如:iter,kkconst,start.temp等).但是,我仍然无法驱散紧密集群的节点.见下图.
我希望找到一些参数来控制吸引力/排斥/重力等,但似乎没有.答案和人物bdemarest在这个问题似乎解决正是这个问题.奇怪的是,在新版本的igraph(coolex,maxdelta,area,repulserad等)中已经弃用了几个看似有用的参数.
有没有人知道如何保持子图很好地分离,同时扩展出足够接近的节点,使它们不重叠?
我有一个shapefile,我强化并使用ggplot2绘制geom_polygon.如何仅绘制此地图的一小部分区域?
我的完整地图看起来很好,但我的小区域搞砸了.
这是一个工作示例:这个小shapefile可以从以下获得:
http://www.mappinghacks.com/data/TM_WORLD_BORDERS_SIMPL-0.2.zip
#read data
spf<-readOGR(getwd(),"TM_WORLD_BORDERS_SIMPL-0.2")
spf@data$id<-rownames(spf@data)
#fortify
spf1<-fortify(spf,region="id")
#full plot
ggplot(spf1)+geom_polygon(aes(long,lat,group=group),colour="grey90")
Run Code Online (Sandbox Code Playgroud)

#subset plot #this is messy since polygons are broken
ggplot(spf1)+geom_polygon(aes(long,lat,group=group),colour="grey90")+
scale_x_continuous(limits = c(-2, 2))+
scale_y_continuous(limits = c(50, 51))
Run Code Online (Sandbox Code Playgroud)

谢谢.
r ×9
ggplot2 ×3
anaconda ×1
conda ×1
dplyr ×1
ggmap ×1
ggvis ×1
igraph ×1
magrittr ×1
pca ×1
python ×1
python-2.7 ×1
python-3.x ×1
r-markdown ×1
shiny ×1
statistics ×1