在生成绘图时,通常需要在导出时将这些绘图放大。这可以按如下方式完成:
png(filename = "plot_name.png", width=1000, height = 800)
print(plot)
dev.off()
Run Code Online (Sandbox Code Playgroud)
不幸的是,情节的元素没有随着它的整体大小而放大。这意味着我最终向 theme() 添加了一堆元素,如下所示。
theme(
legend.position = "bottom",
legend.title = element_text(size=20),
plot.title = element_text(size = 30),
axis.title = element_text(size=20),
axis.text = element_text(size=15),
legend.text = element_text(size=15)
)
Run Code Online (Sandbox Code Playgroud)
有没有办法扩大情节的所有元素及其整体大小?
我使用R生成了一个混淆矩阵,如下所示.
是否可以从该矩阵中检索出假负值61并分配给R中的变量?$ byClass似乎不适合这种情况.谢谢.
Confusion Matrix and Statistics
Reference
Prediction no yes
no 9889 61
yes 6 44
Accuracy : 0.9933
95% CI : (0.9915, 0.9948)
No Information Rate : 0.9895
P-Value [Acc > NIR] : 4.444e-05
Kappa : 0.5648
Mcnemar's Test P-Value : 4.191e-11
Sensitivity : 0.9994
Specificity : 0.4190
Pos Pred Value : 0.9939
Neg Pred Value : 0.8800
Prevalence : 0.9895
Detection Rate : 0.9889
Detection Prevalence : 0.9950
Balanced Accuracy : 0.7092
'Positive' Class : no
Run Code Online (Sandbox Code Playgroud) 我的 ggplot 中有两条独立的回归线,每条线对应一个单独的变量。但是,对应于 的第二条线local
没有延伸到整个图形。是否有解决方法或一种方法可以使两个 ablines 在图形区域上均等地延伸?
ggplot(metrics, aes(x=popDensity, y= TPB, color = factor(type))) + geom_point() +theme_minimal() + stat_smooth(method = "lm", se = FALSE) +
geom_label_repel(aes(label= rownames(metrics)), size=3, show.legend = FALSE) +
theme(axis.title = element_text(family = "Trebuchet MS", color="#666666", face="bold", size=12)) +
labs(x = expression(paste( "Populatin Density ", km^{2})), y = expression(paste("Rating")))+
theme(legend.position="top", legend.direction="horizontal") + theme(legend.title=element_blank())
Run Code Online (Sandbox Code Playgroud)
以下是数据示例:
> dput(metrics)
structure(list(popDensity = c(4308, 27812, 4447, 5334, 4662,
2890, 1689, 481, 4100), TPB = c(2.65, 4.49, 2.37, 2.87, 3.87,
2.95, 1.18, …
Run Code Online (Sandbox Code Playgroud) 我只是在开始使用package likextable
或`stargazer。Bellow 是一个示例数据集,原始数据集要大得多。
set.seed(1)
df <- data.frame(rep(
sample(c(2012,2016),10, replace = T)),
sample(c('Treat','Control'),10,replace = T),
runif(10,0,1),
runif(10,0,1),
runif(10,0,1))
colnames(df) <- c('Year','Group','V1','V2','V3')
Run Code Online (Sandbox Code Playgroud)
我想生成格式良好的表格,显示上述数据集的描述性统计数据。
但是,有没有一种方法xtable
可以直接生成一个表格,我可以在其中查看整个数据集的统计数据,按组(治疗和控制)和年份(2012、2016)分开?或者甚至可以将组和年份结合起来?
或者我应该根据这些设置过滤原始 df 并xtable
在每个设置上运行?
我想要的另一件事是显示变量的中位数,而不是显示mean,以及其他统计数据。是否有可能,或者我是否必须使用 R 手动计算?
任何考虑stargazer
的解决方案都是有效的!
谢谢!
我正在研究一个模拟失踪船只移动的项目.我使用以下代码制作了分布图:
library("ggplot2")
a <- rnorm(1000, 30.2, 2)
b <- rnorm(1000, 10, 5)
y <- (x + a + b) * 0.6
df <- data.frame(x,y)
p <- ggplot(df,aes(x=x,y=y)) +
ggtitle("A Priori Map") + xlab("Longtitude") + ylab("Latitude") +
scale_fill_gradientn(colors = topo.colors(10))
p + stat_binhex(show.legend = T, bins = 20)
Run Code Online (Sandbox Code Playgroud)
这会生成如下地图:
但是,我想用一个点来显示实际的计数,而不是使用颜色显示计数的数量.因此,如果程序"落在"特定点3次,它将显示"3".
如何在R中完成?
给定这样的数据框:
station <- c(1, 2, 3, 1, 2, 3, 1, 2, 2, 2)
obs <- c(12.3, 10.4, 9.8, 15.9, 8.2, 8.4, 6.3, 10.2, 9.0, 8.3)
df <- data.frame(station, obs)
Run Code Online (Sandbox Code Playgroud)
我想像这样创建一个新列run
:
station obs run
1 1 12.3 1
2 2 10.4 1
3 3 9.8 1
4 1 15.9 2
5 2 8.2 2
6 3 8.4 2
7 1 6.3 3
8 2 10.2 3
9 2 9.0 4
10 2 8.3 5
Run Code Online (Sandbox Code Playgroud)
如果我用不同的语言写这个,我的伪代码看起来像这样:
run := 1
if …
Run Code Online (Sandbox Code Playgroud)