简体   繁体   中英

R Grid.Table Plots Overlapping Each Other

just started learning R a few days ago (and new to this site) and have been able to maneuver my way around issues by searching this site/Google, but this issue is really stumping me.

Background: I'm plotting returns from a data.frame into PerformanceAnalytics chart.CumReturns and another data.frame into gridExtra grid.table. I'm trying to arrange them using mfrow=c(2,1) and the chart.CumReturns chart arranges correctly, but the gridExtra grid.table still plots in the center, overlapping the other chart. The code (of what I can post) and picture of the charts is below. Been searching for a resolution for a few hours, trying grid.arrange, but coming up empty on this one...Any help is appreciated.

**Sorry, can't post images. Just imagine the performanceanalytics chart at the top of the plot area with the gridextra table overlapping in the center.

Partial code (realize this prob is not optimized code, just trying to learn the basics now):

library(quantmod)
library(PerformanceAnalytics)
library(gridExtra)

G2 <- read.csv(file = "Data.csv", header = TRUE)

par(mfrow=c(2,1))

chart.CumReturns(cbind(G2DailyReturn,G2MyReturn),
             wealth.index = FALSE,
             geometric = FALSE,
             main = "G2", 
             ylab = "Tick Return",
             par(cex = 1, cex.lab = 0.9),
             cex.axis = 0.55,
             col=rich6equal, 
             legend.loc="topleft")

table.test <- table.CalendarReturns(G2MyMoReturn, digits = 0, 
                                as.perc = FALSE, geometric = FALSE)

grid.table(data.frame(table.test), 
       gpar.coretext = gpar(fontsize=12, fontface="bold", col="black"), 
       gpar.coltext  = gpar(fontsize = 12,col="black", fontface="bold"), 
       gpar.rowtext  = gpar(fontsize = 12, fontface="bold"),
       gpar.corefill = gpar(fill="cadetblue1",alpha=0.5), h.even.alpha = 0.5)

The man, the myth, the legend..."Bo-Finger" with the help of the question below solved this guy. Thanks to agstudy and josh in that thread.

Combine base and ggplot graphics in R figure window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM