作为一个问题,我试图使用以下代码创建图:
chart.demo.sex.age <- ggplot(psf10[!is.na(psf10[,"age_gp"]),c("sex","age_gp")], aes(x=age_gp))
chart.demo.sex.age.f <- chart.demo.sex.age + geom_bar(subset = .(sex =="F"), fill="red")
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_x_discrete(expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(limits=c(0,1500), expand=c(0.05,0))
chart.demo.sex.age.f <- chart.demo.sex.age.f + opts(axis.title.x = theme_blank(),
axis.title.y = theme_blank(),
axis.text.y = theme_blank(),
axis.ticks = theme_blank(),
panel.border = theme_rect(colour="black"),
plot.margin = unit(c(1,0,1,1),"lines"))
chart.demo.sex.age.f <- chart.demo.sex.age.f + scale_y_continuous(trans = 'reverse') + coord_flip()
Run Code Online (Sandbox Code Playgroud)
使用scale_y_continuous(trans = 'reverse'),我无法使用ylimit(即,无法在ylimit中看到调整),我也不知道为什么。有什么建议么?谢谢。
如果我理解正确,该sparkTable包允许多种情节,但仅限于一个系列.因此,例如,如果我的数据集df如下所示:
Run Code Online (Sandbox Code Playgroud)variable value time Level_1 34 1947 Level_1 38 1948 Level_1 17 1949 Level_1 61 1950 Level_1 19 1951 Level_1 80 1952 Level_1 57 1953 Level_1 66 1954
即变量"value"在"变量"级别上的"时间"变化,然后我可以使用以下代码绘制不同级别的"变量"的"值"的迷你图和条形图:
library(sparkTable)
content<-list()
content[['LinePlot']]<-newSparkLine()
content[['BarPlot']]<-newSparkBar()
varType<-rep("value",2)
df<-df[,c("variable","value","time")]
df$time<-as.numeric(as.character(df$time))
dat<-reshapeExt(df,idvar="variable",varying=list(2))
sparkTab<-newSparkTable(dat,content,varType)
plotSparkTable ( sparkTab , outputType = "html", filename = "t1")
Run Code Online (Sandbox Code Playgroud)
但有没有办法在同一输出中绘制多个系列?例如,假设我希望有一个"值"的迷你图,另一个是"值"系列的累积值(计算方法Cumulative_Value = ave(df$value, df$variable, FUN=cumsum))
我有一个像这样的数据集:
col_a col_b col_c
1 abc_boy 1
2 abc_boy 2
1 abc_girl 1
2 abc_girl 2
Run Code Online (Sandbox Code Playgroud)
我只需要根据col_b和获取第一行col_c,然后更改valye col_c,这是这样的:
df[grep("_boy$",df[,"col_b"]) & df[,"col_c"]=="1","col_c"] <- "yes"
但上面的代码不行,因为第一个标准和第二个标准不是来自同一个集合.
我可以通过使用显式循环以愚蠢的方式做到这一点,或者进行"双层"子集化,如下所示:
df.a <- df[grep("_boy$",df[,"col_b"]),] #1
df.b <- df[grep("_boy$",df[,"col_b"],invert=TRUE),] #2
df.a <- df.a[df.a[,"col_c"]=="1","col_c"] <- "yes" #3
df.a <- df.a[df.a[,"col_c"]=="2","col_c"] <- "no" #4
df <- rbind(df.a,df.b) #5
Run Code Online (Sandbox Code Playgroud)
但我不愿意,任何人都可以启发我如何"合并" #1和#3?谢谢.
我试图使用ggplotand生成一些地图sp,我有一个3000+ x 3000+像素原始大小的底图,我也有一些2000+ x 2000+像素。有趣的是,直到现在我仍然无法创建3000+ x 3000+像素 png 文件,因为 R 给了我以下错误:
Error in png(chart.filename, width = basemap.xlength, height = basemap.ylength, :
unable to start png() device
In addition: Warning messages:
1: In png(chart.filename, width = basemap.xlength, height = basemap.ylength, :
Unable to allocate bitmap
2: In png(chart.filename, width = basemap.xlength, height = basemap.ylength, :
opening device failed
Run Code Online (Sandbox Code Playgroud)
这是对R的限制吗?我怎么能熬过去呢?谢谢。
我正在使用带有 R 2.15.0 的 Win7。
我尝试使用 R 中的包为字符串生成 md5 哈希值digest:
> digest::digest('testing',algo='md5')
[1] "06af8dac40480b40834f70a0fa7b35a3"
Run Code Online (Sandbox Code Playgroud)
我访问http://www.md5.cz/并再次执行相同的操作,但输出是ae2b1fca515949e5d54fb22b8ed95575相反的。
我在这里做错了什么?
我使用了下面的脚本并提取了一个 url 列表:
request = urllib2.Request("http://www.dummyurl.com")
pub_lv1 = urllib2.urlopen(request)
pub_lv1_parse = BeautifulSoup(pub_lv1)
pub_lv1_parse = pub_lv1_parse.body.find('table', attrs={"class":"proxy-archive-content-year-list"})
pub_lv1_parse = pub_lv1_parse.findAll('a')
Run Code Online (Sandbox Code Playgroud)
输出如下:
[<a href="/content/by/year/2011">2011</a>,
<a href="/content/by/year/2012">2012</a>,
<a href="/content/by/year/2013">2013</a>,
<a href="/content/by/year/2000">2000</a>,
<a href="/content/by/year/2001">2001</a>,
<a href="/content/by/year/2002">2002</a>,
<a href="/content/by/year/2003">2003</a>,
<a href="/content/by/year/2004">2004</a>,
<a href="/content/by/year/2005">2005</a>]
Run Code Online (Sandbox Code Playgroud)
如您所见,year未排序,我想对它们进行排序,我知道如何使用对字符串列表进行排序,sort但是输出beautifulsoup呢?
我指的是如何从Python中的字符串中提取子字符串的问题?并有进一步的问题。
如果我的字符串是这样的怎么办:
gfgfdAAA1234ZZZsddgAAA4567ZZZuijjk
我想提取1234和4567,它是否存储为列表?
我知道如何使用以下代码获取 Outlook 2010 中的文件夹名称:
import win32com.client
ol = win32com.client.Dispatch("Outlook.Application")
ns = ol.GetNamespace("MAPI")
inbox = ns.Folders(6).Folders(2)
Run Code Online (Sandbox Code Playgroud)
如何在 中添加文件夹Folder(2)?我尝试了http://support.microsoft.com/kb/208520Folders.Add Method中提到的方法但失败了。
作为普通的R用户,我正在学习使用python进行分析,我从卡方开始,并做了以下工作:
> chisq.test(matrix(c(10,20,30,40),nrow = 2))$p.value # test1
[1] 0.5040359
> chisq.test(matrix(c(1,2,3,4),nrow = 2))$p.value # test2
[1] 1
Warning message:
In chisq.test(matrix(c(1, 2, 3, 4), nrow = 2)) :
Chi-squared approximation may be incorrect
> chisq.test(matrix(c(1,2,3,4),nrow = 2),correct = FALSE)$p.value # test3
[1] 0.7781597
Warning message:
In chisq.test(matrix(c(1, 2, 3, 4), nrow = 2), correct = FALSE) :
Chi-squared approximation may be incorrect
Run Code Online (Sandbox Code Playgroud)
In [31]:
temp = scipy.stats.chi2_contingency(np.array([[10, 20], [30, 40]])) # test1
temp[1] # pvalue
Out[31]:
0.50403586645250464
In …Run Code Online (Sandbox Code Playgroud) 是否有可能filter在dplyr一个列的位置?
我知道怎么做就没有 dplyr
iris[iris[,1]>6,]
但我怎么能在dplyr中做到这一点?
谢谢!