Revision | 646bddfa8bc1583d0c8546d13c5f31fc79aacb1d (tree) |
---|---|
Zeit | 2024-12-19 23:03:15 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
I improved the theme.
@@ -1418,37 +1418,115 @@ | ||
1418 | 1418 | |
1419 | 1419 | |
1420 | 1420 | |
1421 | - | |
1422 | -my_ggplot_theme2 <- function(legend_coord){ | |
1423 | - theme_bw()+ | |
1424 | - | |
1425 | - theme(## legend.title = element_text(vjust=1,lineheight=1, size=14 ), | |
1426 | - | |
1427 | - legend.title = element_text(vjust = 1,lineheight=1, | |
1428 | - size=14, margin = margin(t = 4.5)), | |
1429 | - legend.spacing.y = grid::unit(3, "pt"), | |
1430 | - ## legend.text.align = 0.5, | |
1431 | - ## legend.text = element_text(hjust=0.5), | |
1432 | - panel.grid.minor = element_blank(), | |
1433 | - plot.title = element_text(lineheight=.8, size=24, face="bold", | |
1434 | - vjust=1), | |
1435 | - legend.text = element_text(vjust=.4, hjust=0.5, lineheight=1,size = 14 ), | |
1436 | - axis.title.x = element_text(size = 20, vjust=1), | |
1437 | - axis.title.y = element_text(size = 20, angle=90, vjust=1), | |
1438 | - axis.text.x = element_text(size=15, colour="black", vjust=1), | |
1439 | - axis.text.y = element_text(size=15, colour="black", hjust=1), | |
1440 | - legend.position.inside = legend_coord, | |
1441 | - ## legend.position = legend_coord, | |
1442 | - strip.background = element_rect(colour = 'blue', | |
1443 | - fill = 'white', linewidth = 1, linetype=1), | |
1444 | - strip.text.x = element_text(colour = 'red', angle = 0, | |
1445 | - size = 12, hjust = 0.5, | |
1446 | - vjust = 0.5, face = 'bold'), | |
1447 | - strip.text.y = element_text(colour = 'red', angle = 0, | |
1448 | - size = 12, hjust = 0.5, | |
1449 | - vjust = 0.5, face = 'bold'), | |
1421 | +## my_ggplot_theme2 <- function(legend_coord){ | |
1422 | +## theme_bw()+ | |
1423 | + | |
1424 | +## theme(## legend.title = element_text(vjust=1,lineheight=1, size=14 ), | |
1425 | + | |
1426 | +## legend.title = element_text(vjust = 1,lineheight=1, | |
1427 | +## size=14, margin = margin(t = 4.5)), | |
1428 | +## legend.spacing.y = grid::unit(3, "pt"), | |
1429 | +## ## legend.text.align = 0.5, | |
1430 | +## ## legend.text = element_text(hjust=0.5), | |
1431 | +## panel.grid.minor = element_blank(), | |
1432 | +## plot.title = element_text(lineheight=.8, size=24, face="bold", | |
1433 | +## vjust=1), | |
1434 | +## legend.text = element_text(vjust=.4, hjust=0.5, lineheight=1,size = 14 ), | |
1435 | +## axis.title.x = element_text(size = 20, vjust=1), | |
1436 | +## axis.title.y = element_text(size = 20, angle=90, vjust=1), | |
1437 | +## axis.text.x = element_text(size=15, colour="black", vjust=1), | |
1438 | +## axis.text.y = element_text(size=15, colour="black", hjust=1), | |
1439 | +## legend.position.inside = legend_coord, | |
1440 | +## ## legend.position = legend_coord, | |
1441 | +## strip.background = element_rect(colour = 'blue', | |
1442 | +## fill = 'white', linewidth = 1, linetype=1), | |
1443 | +## strip.text.x = element_text(colour = 'red', angle = 0, | |
1444 | +## size = 12, hjust = 0.5, | |
1445 | +## vjust = 0.5, face = 'bold'), | |
1446 | +## strip.text.y = element_text(colour = 'red', angle = 0, | |
1447 | +## size = 12, hjust = 0.5, | |
1448 | +## vjust = 0.5, face = 'bold'), | |
1450 | 1449 | |
1451 | - ) | |
1450 | +## ) | |
1451 | +## } | |
1452 | + | |
1453 | + | |
1454 | + | |
1455 | +## chatgpt revision | |
1456 | + | |
1457 | +my_ggplot_theme2 <- function(legend_coord) { | |
1458 | + theme_bw() + | |
1459 | + theme( | |
1460 | + # Legend settings | |
1461 | + legend.title = element_text( | |
1462 | + vjust = 1, | |
1463 | + lineheight = 1, | |
1464 | + size = 14, | |
1465 | + margin = margin(t = 4.5) | |
1466 | + ), | |
1467 | + legend.text = element_text( | |
1468 | + vjust = 0.4, | |
1469 | + hjust = 0.5, | |
1470 | + lineheight = 1, | |
1471 | + size = 14 | |
1472 | + ), | |
1473 | + legend.spacing.y = grid::unit(3, "pt"), | |
1474 | + | |
1475 | + # Conditionally handle legend position | |
1476 | + legend.position = if (is.character(legend_coord)) { | |
1477 | + legend_coord | |
1478 | + } else if (is.numeric(legend_coord) && length(legend_coord) == 2) { | |
1479 | + "none" # Temporarily set a default | |
1480 | + } else { | |
1481 | + stop("`legend_coord` must be a character or a numeric vector of length 2.") | |
1482 | + }, | |
1483 | + legend.position.inside = if (is.numeric(legend_coord) && length(legend_coord) == 2) { | |
1484 | + legend_coord | |
1485 | + } else { | |
1486 | + NULL | |
1487 | + }, | |
1488 | + | |
1489 | + # Plot title | |
1490 | + plot.title = element_text( | |
1491 | + lineheight = 0.8, | |
1492 | + size = 24, | |
1493 | + face = "bold", | |
1494 | + vjust = 1 | |
1495 | + ), | |
1496 | + | |
1497 | + # Axis titles | |
1498 | + axis.title.x = element_text(size = 20, vjust = 1), | |
1499 | + axis.title.y = element_text(size = 20, angle = 90, vjust = 1), | |
1500 | + | |
1501 | + # Axis text | |
1502 | + axis.text.x = element_text(size = 15, colour = "black", vjust = 1), | |
1503 | + axis.text.y = element_text(size = 15, colour = "black", hjust = 1), | |
1504 | + | |
1505 | + # Strip settings | |
1506 | + strip.background = element_rect( | |
1507 | + colour = 'blue', | |
1508 | + fill = 'white', | |
1509 | + linewidth = 1, | |
1510 | + linetype = 1 | |
1511 | + ), | |
1512 | + strip.text.x = element_text( | |
1513 | + colour = 'red', | |
1514 | + size = 12, | |
1515 | + hjust = 0.5, | |
1516 | + vjust = 0.5, | |
1517 | + face = 'bold' | |
1518 | + ), | |
1519 | + strip.text.y = element_text( | |
1520 | + colour = 'red', | |
1521 | + size = 12, | |
1522 | + hjust = 0.5, | |
1523 | + vjust = 0.5, | |
1524 | + face = 'bold' | |
1525 | + ), | |
1526 | + | |
1527 | + # Grid lines | |
1528 | + panel.grid.minor = element_blank() | |
1529 | + ) | |
1452 | 1530 | } |
1453 | 1531 | |
1454 | 1532 |