R如何使用ggplot强调x轴?

时间:2015-05-18 18:28:25

标签: r ggplot2 axis

如果我使用ggplot,那么x轴(y == 0)的水平线与y的任何其他值相同。我想强调一下这样一个事实:图的底部不是x轴,并且图中的x轴更高。我怎么能这样做?

data.df <- data.frame(Plant = c("Plant1", "Plant1", "Plant1", "Plant2", "Plant2", "Plant2"), Type = c(1, 2, 3, 1, 2, 3), Axis1 = c(0.2, -0.4, 0.8, -0.2, -0.7, 0.1), Axis2 = c(0.5, 0.3, -0.1, -0.3, -0.1, -0.8))

ggplot(data.df, aes(x = Axis1, y = Axis2, shape = Plant, color = Type)) + geom_point(size = 5)

2 个答案:

答案 0 :(得分:6)

您可以用黑线突出显示轴

<?php
$servername = "myservername";
$username = "myusername";
$password = "mypassword";
$dbname = "mydbname";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $conn->beginTransaction();

    // Defining the three request IDs
    $requestid = $_POST['requestid'];
    $requestid1 = $_POST['requestid1'];
    $requestid2 = $_POST['requestid2'];

    // Insert first request ID
    $stmt = $conn->prepare("INSERT INTO requestids (requestid) VALUES (:requestid)");
    $stmt->bindParam(':requestid', $requestid);
    $requestid = $_POST['requestid'];
    $stmt->execute();

    // Insert second request ID
    $stmt = $conn->prepare("INSERT INTO requestids (requestid) VALUES (:requestid1)");
    $stmt->bindParam(':requestid1', $requestid1);
    $requestid = $_POST['requestid1'];
    $stmt->execute();

    // Insert third request ID
    $stmt = $conn->prepare("INSERT INTO requestids (requestid) VALUES (:requestid2)");
    $stmt->bindParam(':requestid2', $requestid2);
    $requestid = $_POST['requestid2'];
    $stmt->execute();

    $conn->commit();
    echo "1";
    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
$conn = null;
?>

答案 1 :(得分:3)

您还可以通过添加例如:

直接更改轴的颜色和宽度
+ theme(axis.line = element_line(colour = 'red', size = 2))