excel图表模板中有堆积柱形图和簇状柱形图,最近我才学会把两个合起来——
步骤:
先把数据列成这种样子——
要堆在一起的项目列在一起(同一行),下一“堆”则到下一行,每“簇”之间空一行。
选中表格,插入—柱形图—堆积柱形图,出来下面这个样子:
选中图中任一序列,右击,设置数据系列格式,把“分类间距”调整为0
然后就可以了。
> install.packages("quantmod")
> library(quantmod)
2.了解一下getFinancials函数
getFinancials(Symbol, env = .GlobalEnv, src = "google",
auto.assign = TRUE,
...)
其中Symbol为上市公司代码,env读取后存放路径,src来源等
3.我们来获取中国石化的财务报表,其黄金股票代码为SHA:600028
> getFin("SHA:600028")
4.我们来看查询函数
viewFinancials(x, type=c('BS','IS','CF'), period=c('A','Q'),subset = NULL)
其中x为存储的文件比如上例的文件为SHA.600028.f,type参数包含三个选项,分别对应谷歌财经能够里的BS(Balance Sheets),IS(Income Statement),CF(Cash Flow Statements)。period参数有两个选项,分别表示年报和季报
> viewFin(SHA.600028.f,"BS","A")
Annual Balance Sheet for SHA:600028
2011-12-31
Monetary Capital 25197
Other Monetary Capital NA
Short-term Investment (Original Value) NA
Devaluation Provision for Short-term Investment NA
Net Short-term Investment NA
Notes Receivable 27961
Dividend Receivable NA
Interest Receivable NA
Accounts Receivable (Original Value) NA
Original Amount of Other Receivables NA
Provision for Bad Debt NA
Net Accounts Receivable 58721
Net Other Receivables 7360
Prepayment 4096
Allowance Receivable NA
Prepaid Tax NA
Internal Receivables NA
Internal Organization Receivables NA
Affiliated Entity Receivables NA
Margin for Futures NA
Trading Position Fee Receivable NA
Inventories NA
Provision of Inventories Impairment NA
Net Inventories 203417
Deferred Costs NA
Transferrable Other Operating Costs NA
Project Construction NA
Net Loss on Disposable Current Assets NA
Long-term Bond Invetment Mature within 1 Year NA
Other Current Assets 836
Total Current Assets 327588
Original Cost of Long-term Equity Investment NA
Original Cost of Long-term Bond Investment NA
Original Cost of Other Long-term Investment NA
Total Original Cost of Long-term Investment NA
Devaluation Provision of Long-term Investment NA
Net Long-term Equity Investment 47458
Net Long-term Bond Investment NA
Net Other Long-term Investment NA
Total Net Long-term Investment NA
Cost-Book Value Differential NA
Equity Investment Differential NA
Original Cost of Fixed Assets NA
Accumulated Depreciation NA
Net Fixed Assets NA
Provision for Fixed Assets Impairment NA
Net Fixed Assets 565936
Project Materials NA
Construction in Process 111311
Disposal of Fixed Assets NA
Net Loss on Disposable Fixed Assets NA
Total Fixed Assets NA
Intangible Assets 34842
Organization Cost NA
Deferred Assets NA
Long-term Deferred Cost 9076
Other Long-term Assets NA
Total Intangible and Other Assets NA
Deferred Income Tax Asset 13398
Total Assets 1130053
Short-term Borrowing 36985
Notes Payable 5933
Accounts Payable 177002
Advance Collections 66686
Commissioned Sales NA
Salaries Payable 1795
Welfare Benefits Payable NA
Dividend Payable NA
Tax Payable 39622
To Withold Taxes NA
Accrued Other Payments NA
Internal Payables NA
Internal Organization Payables NA
Affiliated Entity Payables NA
Other Payables 57662
Commissioned Sales NA
Accrued Cost NA
Engineering Settlement NA
Domestic Notes Settlement NA
International Notes Settlement NA
Estimated Liabilities NA
Long-term Liabilities Mature within 1 Year NA
Other Current Liabilities NA
Bonus and Welfare Funds NA
Total Current Liabilities 429073
Long-term Borrowing 54320
Bond Payable 100137
Long-term Payables NA
Specific Item Payable NA
Revolving Housing Fund NA
Other Long-term Liabilities NA
Total Long-term Liabilities NA
Deferred Interest Income NA
Increase of Deferred Income Tax Liabilities 15181
Total Liabilities 620528
Minority Interest in Equity 35126
Paid-up Share Capital 86702
Capital Reserve 29583
Earned Surplus Reserve 178263
Public Welfare Fund NA
Group Welfare Fund NA
Unidentified Investment Loss NA
Undistributed Profit 178336
Converted Difference on Foreign Currency Statements -1600
Total Shareholders' Equity 509525
Liabilities & Shareholders' Equity 1130053
Non-current Assets within 1 Year NA
Other Items Affecting Current Assets 0
Held-to-maturity Investment NA
Held-to-maturity Investment NA
Real Estate Investment NA
Long-term Receivables NA
Regenerating Biological Assets NA
Oil & Gas Reserves NA
Development Cost NA
Goodwill 8212
Other Non-current Assets 12232
Other Items Affecting Non-current Assets 0
Total Non-current Assets 802465
Trading Financial Liabilities NA
Interest Payable NA
Non-current Liabilities Mature within 1 Year 43388
Other Items Affecting Current Liabilities NA
Other Non-current Liabilities 3436
Other Items Affecting Non-current Liabilities 0
Total Non-current Liabilities 191455
Less: Treasury Stock NA
Other Items Affecting Equity NA
Trading Financial Assets NA
Inventories - Consumable Biological Assets NA
Parent Company Equity 474399
Floating Rights of Stock with Different Voting Rights NA
Deferred Income NA
Less: Investment Returned NA
Special Reserve 3115
2010-12-31
Monetary Capital 18140
Other Monetary Capital NA
Short-term Investment (Original Value) NA
Devaluation Provision for Short-term Investment NA
Net Short-term Investment NA
Notes Receivable 15950
Dividend Receivable NA
Interest Receivable NA
Accounts Receivable (Original Value) NA
Original Amount of Other Receivables NA
Provision for Bad Debt NA
Net Accounts Receivable 43093
Net Other Receivables 9880
Prepayment 5247
Allowance Receivable NA
Prepaid Tax NA
Internal Receivables NA
Internal Organization Receivables NA
Affiliated Entity Receivables NA
Margin for Futures NA
Trading Position Fee Receivable NA
Inventories NA
Provision of Inventories Impairment NA
Net Inventories 156546
Deferred Costs NA
Transferrable Other Operating Costs NA
Project Construction NA
Net Loss on Disposable Current Assets NA
Long-term Bond Invetment Mature within 1 Year NA
Other Current Assets 594
Total Current Assets 249450
Original Cost of Long-term Equity Investment NA
Original Cost of Long-term Bond Investment NA
Original Cost of Other Long-term Investment NA
Total Original Cost of Long-term Investment NA
Devaluation Provision of Long-term Investment NA
Net Long-term Equity Investment 45037
Net Long-term Bond Investment NA
Net Other Long-term Investment NA
Total Net Long-term Investment NA
Cost-Book Value Differential NA
Equity Investment Differential NA
Original Cost of Fixed Assets NA
Accumulated Depreciation NA
Net Fixed Assets NA
Provision for Fixed Assets Impairment NA
Net Fixed Assets 540700
Project Materials NA
Construction in Process 89599
Disposal of Fixed Assets NA
Net Loss on Disposable Fixed Assets NA
Total Fixed Assets NA
Intangible Assets 27440
Organization Cost NA
Deferred Assets NA
Long-term Deferred Cost 7560
Other Long-term Assets NA
Total Intangible and Other Assets NA
Deferred Income Tax Asset 15578
Total Assets 985389
Short-term Borrowing 29298
Notes Payable 3818
Accounts Payable 132528
Advance Collections 57324
Commissioned Sales NA
Salaries Payable 7444
Welfare Benefits Payable NA
Dividend Payable NA
Tax Payable 33814
To Withold Taxes NA
Accrued Other Payments NA
Internal Payables NA
Internal Organization Payables NA
Affiliated Entity Payables NA
Other Payables 54871
Commissioned Sales 1000
Accrued Cost NA
Engineering Settlement NA
Domestic Notes Settlement NA
International Notes Settlement NA
Estimated Liabilities NA
Long-term Liabilities Mature within 1 Year NA
Other Current Liabilities NA
Bonus and Welfare Funds NA
Total Current Liabilities 325627
......
5.我们来查看一下黄金企业的利润表,仍然使用viewFin函数
> viewFin(SHA.600028.f,"IS","A")
Annual Income Statement for SHA:600028
2011-12-31
Sales Revenue 2505683.00
Discount and Allowance NA
Net Revenue from Main Operation NA
Less: Cost of Goods Sold 2093199.00
Sales Tax & Other Charges 189949.00
Profit (Loss) from Principal Operations NA
Income from Other Operation NA
Inventory Falling Price Loss NA
Business Expenses NA
Administrative Expenses 63083.00
Financial Expenses 6544.00
Period Expense NA
Purchase Expenses NA
Exchange Gains or Losses NA
Operating Profit 100966.00
Investment Income 4186.00
Gains and Loss of Futures NA
Subsidy Income NA
Non-Operating Revenue 3411.00
Income Adjustment for Previous Years NA
Non-operating Expenses 1739.00
Net Non-operating Income NA
Profits Distribute to Other Firms NA
Preceding Year Income Tax Adjustment NA
Total Profit 102638.00
Income Tax 25774.00
Minority Interest 5167.00
Subsidiary Losses NA
Special Funds Payable NA
Bonus and Welfare Funds NA
Merger Profit NA
Unidentified Investment Loss NA
Reimbursement of Income Tax NA
Losses of Subsidiaries shouldn't take by Parent Company NA
The Revenue to Subsidiaries Offset Excess Deficit NA
Net Profit 76864.00
Beginning Undistributed Profit NA
Other Transferred in 0.00
Transferred from Surplus Reserve NA
Beginning Undistributed Profit Adjustment NA
Reduction of Registered Capital Reduced Undistributed Profit NA
Translation Reserve NA
Adjustments on Extraordinary Items NA
Profit Distribution before Established Corporation NA
Revolving Housing Fund NA
Profit Available for Dividend NA
Appropriation of Statutory Surplus Reserves NA
Appropriation of Statutory Welfare Fund NA
Withdrawal of Employee Award and Benefits Fund NA
Appropriation of Reserve Fund NA
Appropriation of Enterprise Expansion Fund NA
Distribution of Profits Available for Shareholders NA
Preferred Stock Dividends Payable NA
Appropriation of Other Surplus Reserve NA
Appropriation of Ordinary Shares Dividend NA
Conversion of Common Stock Dividend into Stock NA
Undistributed Profit NA
Disposal of Departments or Invested Firms NA
Loss Due to Natural Disaster NA
Accounting Policy Change Increase (Decrease) Total Profit NA
Accounting Estimates Change Increase (Decrease) Total Profit NA
Loss on Arrangement NA
.....
6.查看现金流
> viewFin(SHA.600028.f,"CF","A")
Annual Cash Flow Statement for SHA:600028
2011-12-31
Cash Received for Goods Sold and Services Rendered 2889482
Rental Charge 437
Received and Returned Value Added Tax NA
Tax Refund Received excluding Value Added Tax NA
Tax Refund Received NA
Receipts from Other Business Activities 12316
Cash Inflows from Operating Activities Subtotal 2902235
Cash Outflow for Goods & Services Purchased 2398623
Cash Payment under Operating Lease 12611
Cash Salaries 41718
Value Added Tax Paid 71311
Income Tax Paid 29798
Tax Paid excluding Value Added & Income Tax NA
Various Taxes Paid 176474
Other Operating Cash Outflow 20519
Cash Outflow for Operating Activities Subtotal 2751054
Net Operating Cash Flow 151181
Divestment Cash Inflow 3039
Cash Received for Dividend or Profit Distribution 2961
Cash Received for Bond Interest Income NA
Cash Received for Investment Income NA
Intangible and Other Long-term Assets 1216
Other Investing Cash Inflow 11646
Cash Outflow from Investment Activities Subtotal 18862
Intangible and Other Long-term Assets 142813
Cash Payment for Equity Investment NA
Cash Payment for Bond Investment NA
Investing Cash Outflow 7488
Other Investing Cash Outflow 9569
Cash Outflow from Investment activities Subtotal 159870
Net Cash from Investment Activities -141008
Cash Raised from Attracting Equity Investment NA
Subsidiaries Financing from Minority Shareholders
....
有了数据就可以进行下一步的工作了,看到这样现实的数据首先要把它们规范化,那就要根据个人分析的目的操作了
> mtscaled <- as.matrix(scale(mtcars))
2.创建热点图,去除对列重新排序的默认项。
> heatmap(mtscaled, Colv=F, scale='none')
需要说明是,默认况下,R会同时根据列和行做聚类热点图,而且会依据均值对系统树进行重新排序,Colv=F表示拒绝重新排序。如果我们的数据是时间序列等已经有序的数据,我们可能就不需要对列排序,仅需要对行聚类,这样我们可以把参数设为Colv=NA,从上图我们可以看到hp、cyl、disp的关系较近,而且马力越大,速度越快越耗油。
3.如果我们需要指定聚类数目,比如我要把上图以行聚类的第一个分支的两簇分别做图,那我们就需要hclust和cutree函数,而hclust函数必须根据距离矩阵执行
#首先以行聚类
> hc.rows <- hclust(dist(mtscaled))
#对矩阵转置,并重新以列聚类
> hc.cols <- hclust(dist(t(mtscaled)))
#对第一个分支聚类做热点图
> heatmap(mtscaled[cutree(hc.rows,k=2)==1,], Colv=as.dendrogram(hc.cols), scale='none')
对第二个分支聚类做热点图
> heatmap(mtscaled[cutree(hc.rows,k=2)==2,], Colv=as.dendrogram(hc.cols), scale='none')
如果你不喜欢这套热点图的颜色,你可以利用一下函数首先修改默认颜色再做图
> palette <- colorRampPalette(c('#f0f3ff','#0033BB'))(256)
> heatmap(mtscaled, Colv=F, scale='none', col=palette)
或者通过col参数直接设置
> heatmap(mtscaled[cutree(hc.rows,k=2)==2,], Colv=as.dendrogram(hc.cols), scale='none',col=topo.colors(100))
如果你要添加颜色图例的话你可以选择heatmap.2,它在gplot包里。
然后选择连接到现有数据库,在下面的对话框中选择Microsoft Office Access 2007格式,然后选择继续。
然后在浏览中选择自己的Microsoft Office Access 2007的路径,打开然后继续
然后就可以根据需要图中所示表格进行编辑了,以后就可以双击自己新建的ODF数据库进行编辑。
1.查看data.frame的开头> head(df)sequence start end 1 chromosome 1450 2112 2 chromosome 41063 41716 3 chromosome 62927 63640 4 chromosome 63881 64807 5 chromosome 71811 72701 2.选择data.frame特定的列> df[,c('sequence','start','end')]sequence start end 1 chromosome 1450 2112 2 chromosome 41063 41716 3 chromosome 62927 63640 4 chromosome 63881 64807 5 chromosome 71811 72701 ... 3.选择同时查看data.frame的列和行> df[566:570,c('sequence','start','end')]sequence start end 566 chromosome 480999 479860 567 chromosome 481397 480999 568 chromosome 503053 501275 569 chromosome 506476 505712 570 chromosome 515461 514277 4.想SQL那样选择符合特定标准的行df[df$value>3.0,]
sequence strand start end common_name value 199 chromosome + 907743 909506 hutU 3.158821 321 chromosome + 1391811 1393337 nadB 3.092771 556 chromosome - 431600 431037 apt 3.043373 572 chromosome - 519043 518186 hbd1 3.077040 5.选择包含特定内容的行列:找到tRNA> df[grep("trna", df$common_name, ignore.case=T),]sequence strand start end common_name value 18 chromosome + 115152 115224 Asn tRNA -0.461038128 19 chromosome + 115314 115422 Ile tRNA -0.925268307 31 chromosome + 167315 167388 Tyr tRNA 0.112527023 32 chromosome + 191112 191196 Ser tRNA 0.986357577 ... 6.复制行名称:行名成不仅在data.frame中使用,在矩阵中同样适用。 我们创建一个矩阵: > a = matrix(1:18, nrow=6, ncol=3) > rownames(a) <- c('a', 'a', 'a', 'b', 'b', 'b') > colnames(a) <- c('foo', 'bar', 'bat') > a foo bar bat a 1 7 13 a 2 8 14 a 3 9 15 b 4 10 16 b 5 11 17 b 6 12 18 如果我们只按照行名称选择查看的话,R反馈回来的只有符合该名称的第一行 > a['a',] foo bar bat 1 7 13 > a['b',] foo bar bat 4 10 16 但如果这样查询就能查看所有符合行名称的内容 > a[rownames(a)=='a',] foo bar bat a 1 7 13 a 2 8 14 a 3 9 15